File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shift operator

 
Suhita Reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

>> : x>>y means x/2powery.
<< : x<<y means x*2powery.
>>> : x>>>y means?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and remember everyone - this is a 1.4 topic but it's NOT a 5.0 topic
 
kanon in
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic