Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bit Shifting question

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, thank you for reading

i have a question which deal with bit shifting


x=1 ==> 0000 0000 0000 0000 0000 0000 0000 0001

my question is, let say right shift x to 31 bits, will the bit shift after the rightmost bit and then will continue the shift from leftmost ?

after right shift to 31 bits, would it be 0000 0000 0000 0000 0000 0000 0000 0010 ?
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is, let say right shift x to 31 bits, will the bit shift after the rightmost bit and then will continue the shift from leftmost ?

You are describing a right circular shift. Java does not do this. Bits shifted past the end of a word go into the bit bucket, where they will be reused the next time you reboot your computer.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mike, thanks for answering , based on


can you please clarify further details? what do you means bit bucket ? and how could it be reuse during enxt time reboot the computer ?
 
Henry Wong
author
Marshal
Pie
Posts: 21398
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alvin chew:
can you please clarify further details? what do you means bit bucket ? and how could it be reuse during enxt time reboot the computer ?


Alvin,

A "bit bucket" is slang for thrown away. A.K.A. "/dev/null", "round file", "trash can", etc...

Mike,

Maybe you should add a ... You never know when jokes may be taken seriously.

Henry
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for misunderstanding
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic