-5>如何2 === -2?
在MDN文档中,下面有此示例在右移动运算符下。
const a = 5; // 00000000000000000000000000000101
const b = 2; // 00000000000000000000000000000010
const c = -5; // -00000000000000000000000000000101
console.log(a >> b); // 00000000000000000000000000000001
// expected output: 1
console.log(c >> b); // -00000000000000000000000000000010
// expected output: -2
5>> 2
是有道理的,因为您将数字向右移动2个空间。在 -5>>的第二个示例中2
,为什么即使它是>> 2
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像约翰尼(Johnny)的一面一样,您可能需要检查两者的补充规则。最左侧的数字可能是
0
的内部<代码> 1 。您可能需要用-9
检查示例此示例将帮助您更好地理解。Just like Johnny side, you might want to check the Two's complement rule. The number in left most might be
1
inside of0
. You might want to check the example with-9
this example will help you understand better.