Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes bitwise shift operations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "bitwise shift operations" Watch "bitwise shift operations" New topic

bitwise shift operations

Rowan Chattaway
Ranch Hand

Joined: Jan 18, 2002
Posts: 75
Can someone quickly explain to me the behavior of bitwise shift operations.
For example:

13 >> 1 = 6
13 >> 2 = 3
13 >> 3 = 1

I understand the logic in how these bits are shifted and the end result in these cases.
I also understand why if you shift over 3 then you should get 0 back.

However, my question is this: when you bitwise shift 13 to the right by 32, why do you get 13?

13 >> 32 = 13.

The early bird may get the worm, but the second mouse gets the cheese.........<br /> <br />Sun Certified Programmer for Java 2 Platform<br />Sun Certified Web-Component Developer for J2EE Platform
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Try reading through this.

SCJP Tipline, etc.
I agree. Here's the link:
subject: bitwise shift operations
It's not a secret anymore!