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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 17:31:06  来源:igfitidea点击:

Double more-than symbol in JavaScript

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

Javascript Bitwise Operators

Javascript 按位运算符

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 >> 1equals 2because 4 is 100in 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(箭头键)时,这将是假的,否则为真。

回答by Jim Davis

It's the Bitwise shift operator (see here).

它是按位移位运算符(请参阅此处)。

Now, as to exactly what it's doing here I'm not sure... I'm sure some of our larger-brained bretheren that actually finished college could help us out with that. ;^)

现在,至于它到底在做什么,我不确定……我敢肯定,我们一些真正完成大学学业的大脑袋弟兄可以帮助我们解决这个问题。;^)