JavaScript 中的双倍以上符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5528119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Double more-than symbol in JavaScript
提问by bcm
What does this: >> mean in JavaScript?
这是什么:>> 在 JavaScript 中是什么意思?
Seen in this context:
在这种情况下看到:
document.onkeydown = document.onkeyup = function(e,v,y,k) {
(i=e.keyCode-37)>>2 || (keys[i] = e.type[5]&&1||(0))
}
采纳答案by amosrivera
Left shift a << b Shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.
Sign-propagating right shift a >> b Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off.
左移 a << b 将二进制表示中的 a 向左移动 b (< 32) 位,从右移零。
符号传播右移 a >> b 将二进制表示中的 a 右移 b (< 32) 位,丢弃移出的位。
回答by M?rten Wikstr?m
>>
is the bitwise right shift operator.
>>
是按位右移运算符。
For example: 4 >> 1
equals 2
because 4 is 100
in binary notation, which is shifted one bit to the right, giving us 10
= 2
例如:4 >> 1
等于,2
因为 4 是100
二进制表示法,它向右移动一位,给我们10
=2
回答by Phssthpok
(i=e.keyCode-37)>>2
This code is discarding the two least significant bits of i (similar to dividing by 4), and comparing the result to zero. This will be false when the key pressed is 37-40 (arrow keys), and true otherwise.
此代码丢弃 i 的两个最低有效位(类似于除以 4),并将结果与零进行比较。当按下的键为 37-40(箭头键)时,这将是假的,否则为真。