GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes shift operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "shift operators" Watch "shift operators" New topic
Author

shift operators

Tom Graziose
Ranch Hand

Joined: Aug 24, 2000
Posts: 40
Can someone clear this up for me.
Why is the result of "1 << 32" 1?
what happened to the x << y translates to x*2ey ???
Brett Knapik
Ranch Hand

Joined: Oct 15, 2000
Posts: 255
when you change those bits it makes the int value wrap around due to that you are making value bigger than an int can hold.
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Lahcen Mannou
Greenhorn

Joined: Oct 09, 2000
Posts: 7
Hi,
The expression "1 << 32" is equivalent to "1 << (32%32)",
so because 32%32 = 0, the result is 1.
Tom Graziose
Ranch Hand

Joined: Aug 24, 2000
Posts: 40
Thanks Brett and Lahcen
 
GeeCON Prague 2014
 
subject: shift operators