Hi,
Here are the points to remember.
1.Any variable of type int occupies 4 bytes which is 4*8 bits i.e 32 bits.
Bit
pattern of an Integer:
Example:
0000 1111 0000 1111 0000 1111 0000 1111 ==> 32 bits
Now,when you need to perform bit shift operation ( be it << or >> shift ), you are left with only 31 bits i.e you have only 31 positions available for shift operation.
This is the reason why you cannot shift more than 31 bits on an integer variable.
So, whenever the number of bits to be shifted is more than 31 say 32, you need to shift (Number of bits to be shifted)%32
which in our case is 32%32 i.e zero.
Example:
Unsigned right shift operation on an int variable x.
1. int x=-4;
x>>>32;
Since the number of bits to be shifted is more than 31, you need to shift 32%32 which is zero.
So the above shift is equivalent to,
int x = -4;
x>>>0;
Since no right shift operation is performed, the result is same as the original number i.e. -4.
FYI: The statement,
"Unsigned right shift operation on a Negative integer always returns a Positive integer" - is FALSE.
- Suresh Selvaraj