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

标签 java javascript bit-manipulation bit-shift

<分区>

我以前看过 >>>>>>两者有何区别以及何时使用?

最佳答案

其他人提供了解释。 >>> 移动所有位,甚至是符号位(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));

输出如下:

x >>> 3 = 536870904
x >> 3 = -8
11111111111111111111111111000
11111111111111111111111111111000

关于java - 2个箭头和3个箭头的位移位有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22307256/

相关文章:

java - Spark 时间戳差异

java - Intellij Idea 评论错误

java 安全客户端套接字身份验证

java - 在 Eclipse 中调试 List<Class> 对象?

javascript - 将视差滚动与 "mouse tracker"相结合

c - 有没有更有效的方法将 char 扩展为 uint64_t?

go - 在 Go 中将 uint16 转换为 int16 的正确方法

javascript - 让表单在无状态 react 组件中提交数据的正确方法是什么?

javascript - 使侧导航高度匹配 Angular ui-view div 高度

php - bool 值的按位运算