Can somebody explain this with an eg? The value returned by >>> will never be negative as long as the value of the right operand is not divisible by 32. I would like to know if there are any chances of getting a negative number when the right operand is divisible by 32. Thanks
Yep, you can get a negative number with >>> when right-hand value is divisible by 32. The reason is that if the left hand value is an int, then you can only shift by 31 places at most. A shift by 32 places does nothing to the value. If you try to shift an int by 33 places than it does a shift by the value 32%33 or 1. So if you have: -1 >>> 32 or -1 >>> 64 etc... you will get -1 becuase it is not performing the shift at all. Any other value on the right hand side will make the result a positive. Bill
Hi, Ash As Bill said, you can shift a given integral value by using shift-right-with-zero-fill(>>>). If the right operand is equals 32, then the original value is the result. when the right operand is bigger than 32 but not the integral times of 32, the result is the result of >>>(rOp -32). Maybe the following can help u undertand it: