<分区>
Signed right shift 5 >> 1 0101 >> 1 0010 2
>>> Zero fill right shift 5 >>> 1 0101 >>> 1 0010 2
These examples appear to be same!I want to know difference between these two.
标签 javascript
<分区>
Signed right shift 5 >> 1 0101 >> 1 0010 2
>>> Zero fill right shift 5 >>> 1 0101 >>> 1 0010 2
These examples appear to be same!I want to know difference between these two.
最佳答案
对于 >>>
,0
从左边移入。
对于 >>>
,最左边的位的副本从左边移入。如果最左边的位是 0,则与 >>>
相同,但如果最左边的位是 1,则不同。例如:
// in binary, -5 is represented as 111111111111... on the left
console.log(-5 >> 4); // -5 >> 4 results in the left side still looking like 111111...
console.log(-5 >>> 4); // -5 >>> 4 shifts in 5 zeros: 000001111111...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
关于javascript - javascript 中 >> 和 >>> 运算符有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49584680/