>> 和有什么不一样?和>> JavaScript 中的运算符
运行以下 JavaScript 代码在两种情况下都会显示 63
:
alert( 0xff >> 2 );
alert( 0xff >>> 2 );
>>
和 >>>
之间有什么区别?他们的结果似乎是平等的。
Running the following JavaScript code shows 63
in both cases:
alert( 0xff >> 2 );
alert( 0xff >>> 2 );
What is the differences between >>
and >>>
? Their results seem to be equal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
>>
是按位运算符,它将位向右移动。右侧的所有位都会丢失。>>>
与>>
执行类似的操作,但它是无符号的,这意味着它的范围从 0 到 232-1 而不是 +/- 231-1。要查看第一个语句的实际结果,让我们使用按位运算符对数字进行取整:
因此,当超出范围的上限时,计算将在其下限继续进行,反之亦然(例如
<<
)。下图显示了当您使用 n = (n + 1) >> 时会发生什么情况0 和>>> 0
,对于从最低边界开始的n
。>>
is a bitwise operator, which shift the bits to the right. Any bits at the right are lost.>>>
does the similar thing as>>
, but it's unsigned, which means that it ranges from 0 to 232-1 instead of +/- 231-1.To see the result of my first statement in action, let's use the bitwise operator to floor a number:
So, when the upper boundary of a range is exceeded, the calculation will continue at its lower range, and vice versa (eg
<<
). The following illustrates shows what happens when you usen = (n + 1) >> 0
, and>>> 0
, forn
starting at the lowest boundary.它是 无符号右移运算符。
It is the Unsigned Right Shift Operator.
一些链接:
A few links: