What do “>>” and “<<” mean in Javascript?

后端 未结 10 828
清酒与你
清酒与你 2020-11-29 13:39

I have a piece of Javascript code I\'m trying to understand

// read big-endian (network byte order) 32-bit float
readFloat32 = function(data, offset) {
    v         


        
10条回答
  •  迷失自我
    2020-11-29 13:55

    They are bitshift operators. Numbers in the computer are represented in binary. Shifting left is equivalent to multiplying by 2 and shifting right is equivalent to dividing by 2.

    For example, the number 8 is 1000 in binary. Shift left << by 3 would yield 1000000 which is 64. Shift right by 2 would yield 10 which is 2.

提交回复
热议问题