做这些的JavaScript位运算符吗? [英] What do these JavaScript bitwise operators do?

查看:108
本文介绍了做这些的JavaScript位运算符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆