做这些的JavaScript位运算符吗? [英] What do these JavaScript bitwise operators do?
问题描述
-
X<< = Y(X = X<< Y)
-
X>> = Y(X = X>> Y)
-
X>>> = Y(X = X>>> Y)
-
X'放大器; = Y(X = X&安培; Y)
-
X ^ = Y(X = X ^ Y)
-
X | = Y(X = X | Y)
做这些不同的运营商吗?
<<,>>
位移位 的左侧和右侧,分别为。如果想象左操作数作为比特的二进制序列,你的移的那些向左或向右通过右操作数指示的比特的数量。
&放大器;,^,|
这是按位和, 或,分别为异,然后。你能想到的&安培;
和 |
作为同行&放大器;&安培;
和 ||
,但他们会将自己的操作数为位向量,并在每个位执行逻辑运算。没有 ^ ^
运营商,但这种操作是异或独家或的。你可以认为一个XOR B为A或B,但不能同时。
x <<= y (x = x << y)
x >>= y (x = x >> y)
x >>>= y (x = x >>> y)
x &= y (x = x & y)
x ^= y (x = x ^ y)
x |= y (x = x | y)
What do these different operators do?
<<, >>
Bit shift left and right, respectively. If you imagine the left operand as a binary sequence of bits, you are shifting those to the left or right by the number of bits indicated by the right operand.
&, ^, |
These are bitwise and, xor, and or, respectively. You can think of &
and |
as the counterparts to &&
and ||
, except that they will treat their operands as bit vectors, and perform the logical operations on each of the bits. There is no ^^
operator, but this operation is "xor" or "exclusive or". You can think of "a xor b" as "a or b, but not both".
这篇关于做这些的JavaScript位运算符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!