Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shifting Operators?

Status
Not open for further replies.

ietprofessional

Programmer
Apr 1, 2004
267
US
I'm trying to get Java certified and I'd like someone to explain to me why a programmer would use shifting operators?

<<, >>, >>>

I'm learning how they work but don't know why I would use them in the real world, unless it was for encrypting a number or something.

Thanks,

Harold
 
In Java, they are used when you need to manipulate bytes on a low level. As you suggested, cryptography is one use.

I've been programming Java for 3 years and have only ever used them once, when maipulating byte values on a TCP/IP stream.

Generally you won't use them - but its good to know how they work, as you can understand more about computing from them.



--------------------------------------------------
Free Database Connection Pooling Software
 
Well, not in Java, as you won't do much bit processing on a such high level language.

But in other terms, they have real applications: number generation, Turing machines, streaming simulation, etc.

Cheers.

Dian
 
I occasionally use shifting when reading a nonstandard size value from a stream of telemetry. For example, I receive a 32bit word. The first 15 bits are a day counter; the last 17 bits are a seconds of day value (86400 seconds in 24 hours; 2^16=65536; 2^17=131072). I shift left by 15, then left by 15 and read the integer as a 32 bit word with leading zeros. I shift right by 17 and read the (day) integer as a 32 bit word.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top