2个箭头和3个箭头的按位移位有什么区别?

hap*_*ore 5 javascript java bit-manipulation bit-shift

我已经看到>>>>>之前.有什么区别,什么时候使用?

mtt*_*brd 7

其他人提供了解释.>>>移位所有位,甚至是符号位(MSB).>>保持标志位到位并移动所有其他标志.最好用一些示例代码解释:

int x=-64;

System.out.println("x >>> 3 = "  + (x >>> 3));
System.out.println("x >> 3 = "  + (x >> 3));
System.out.println(Integer.toBinaryString(x >>> 3));
System.out.println(Integer.toBinaryString(x >> 3));
Run Code Online (Sandbox Code Playgroud)

输出如下:

x >>> 3 = 536870904
x >> 3 = -8
11111111111111111111111111000
11111111111111111111111111111000
Run Code Online (Sandbox Code Playgroud)


Pat*_*icz 5

双箭头“>>”和三箭头“>>>”是在 32 位整数上定义的,因此对变量执行这些操作会将它们从非数字“转换”为数字。此外,JavaScript 数字存储为双精度浮点数,因此这些操作也会导致您丢失任何高于 32 的精度位。“>>”保留符号位(结果是有符号整数),而“>>>”则不保留符号位(结果是无符号整数)。

http://msdn.microsoft.com/en-us/library/342xfs5s%28v=vs.94%29.aspx

为了更好的解释:/sf/answers/127593861/