This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Shift operator" Watch "Shift operator" New topic
Author

Shift operator

Suhita Reddy
Ranch Hand

Joined: Jun 09, 2006
Posts: 60
Hi,

There are 3 shift operators.>>,>>>,<<.

>> : x>>y means x/2powery.
<< : x<<y means x*2powery.
>>> : x>>>y means?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11448
    
  16

I forget which is which, but one of >> and >>> maintains the sign bit, and one doesn't.

Here is a quick overview i found when googling "java shift operators"

also, I'm not sure i'd really say that x>>y means x / 2^y. try it with y=32 (i think that's the right value), and you'll notice that nothing actually happens.
[ December 15, 2006: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8879
    
    5
and remember everyone - this is a 1.4 topic but it's NOT a 5.0 topic


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
kanon in
Greenhorn

Joined: Dec 17, 2006
Posts: 10
hi

x << y is left shift ( x*pow(2,y))
x >> y is right shift( x/pow(2,y)) with sign fill operator.
i.e while shiftg bits right the lower bits are discarded and higher bits are placed by 1 or 0 depending upon the sign bit of the no. here (x)

while in x >>> y , its right shift with Zero fill operator.
i.e lower bits will b discarded but higher bits will b replaced by 0 regardless of the sign bit of no. here (x).

Detail topic you can find in Khalid Mughal or Kathy Sierra.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shift operator