对于以下程序:
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);
}
Run Code Online (Sandbox Code Playgroud)
我得到如下输出:
x = -1
y = 2147483647
Run Code Online (Sandbox Code Playgroud)
我得到的结果-1>>>1是2147483647.如果它是必须移位的符号位,正如我所知,结果应该是1073741824.为什么它是2147483647呢?
下图更清楚地说明了我的问题: