For the program below:
public class ZeroFillRightShift
{
public static void main(String args[])
{
int x = -1;
int y = x>>>1;
System.out.println("x = " + x);
System.out.println("y = " + y);
}
I get the output as follows:
x = -1
y = 2147483647
The result that I got for -1>>>1 is 2147483647. If it’s the sign bit that has to be shifted, as I learned, the result should be 1073741824. Why is it 2147483647 then?
The following image illustrates my problem more clearly:
