wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Shift operator