This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shift operator 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 operator " Watch "Shift operator " New topic
Author

Shift operator

Rakesh Ameta
Greenhorn

Joined: May 10, 2006
Posts: 9
Hi all,
following code:
--------------------------------

-----------------------------------
is printing 0 (zero) ,can anyone explain,how it is doing?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You should be able to work out why if you read this from the Java Language Specification:

If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (�15.22.1) with the mask value 0x1f. The shift distance actually used is therefore always in the range 0 to 31, inclusive.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Rakesh Ameta
Greenhorn

Joined: May 10, 2006
Posts: 9
thanks Barry
 
GeeCON Prague 2014
 
subject: Shift operator