posted 19 years ago
Hi,
Try this
Computation of expression n>>s
For nonnegative values of n, this is equivalent to truncating integer division, as computed by the integer division operator /, by two to the power s,
and for negative values of n, this is equivalent to truncating integer division, as computed by the integer division operator /, by two to the power s and -1,
for example -10>>2 = -3 is compuatated as [ (-10 / (2 * 2) ) - 1 ] = -3
and 10>>2 = 2 is computated as [ 10 / (2 * 2) ] = 2
and Computation of expression n>>>s
The value of n>>>s is n right-shifted s bit positions with zero-extension. If n is positive, then the result is the same as that of n>>s; if n is negative, the result is equal to that of the expression (n>>s)+(2<<~s) if the type of the left-hand operand is int, and to the result of the expression (n>>s)+(2L<<~s) if the type of the left-hand operand is long. The added term (2<<~s) or (2L<<~s) cancels out the propagated sign bit. (Note that, because of the implicit masking of the right-hand operand of a shift operator, ~s as a shift distance is equivalent to 31-s when shifting an int value and to 63-s when shifting a long value.)
Regards,
Piyush Jain<br /> <br />Being happy doesn't mean everything's perfect. It means you've decided to see beyond the imperfections.