• Post Reply Bookmark Topic Watch Topic
  • New Topic

Shift Operators  RSS feed

 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, in practical terms...

x >> 4 (is equivalent to) x/(2^4)
x << 3 (is equivalent to) x*(2^3)

So, what would be the practical expression that is equivalent to the unsigned right shift?

x >>> 5 (is equivalent to) ???
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is a "practical expression" for the unsigned shift. All it means is that you "zero-fill" from the left as opposed to "sign bit fill."
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, after shifting (x >>> y) you need to mask off the high y bits (set them to zero). As James said, there's no "practical" expression, but maybe you should give it a shot as a good exercise in bit fiddling in Java.
 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just passed the SCJP1.4 exam and wanted to post this appreciation note to thank everyone who helped me understand Java a little better. Without your help this personal achievement wouldn't be possible.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!