What do the << and >> operator do? [duplicate]

こ雲淡風輕ζ 提交于 2019-11-28 11:40:39

问题


This question already has an answer here:

  • What do these JavaScript bitwise operators do? 3 answers

I came across some code as noted below and am confused as to what it's doing.

hash += (hash << 10);

回答1:


It's a Bitwise Operator.

Here's an example from the MDN (linked to above):

     9 (base 10): 00000000000000000000000000001001 (base 2)
                  --------------------------------
9 << 2 (base 10): 00000000000000000000000000100100 (base 2) = 36 (base 10)

See how the 1s have shifted?




回答2:


This is one of the JavaScript bitwise operators:

Left Shift

a << b

Shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.



来源:https://stackoverflow.com/questions/9606050/what-do-the-and-operator-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!