What's value of 1<<1? how to calculate it?

This question already has an answer here:

  • What are bitwise shift (bit-shift) operators and how do they work? 8 answers

  • It's just a bit-shift operation.

    1 << 0 = 1
    1 << 1 = 2
    1 << 2 = 4
    1 << 3 = 8
    etc...
    

    or in binary view

    00000001 << 1 = 00000010
    00000001 << 2 = 00000100
    00000001 << 3 = 00001000
    

    This is left shift operator.

    All the bits are shifted one place toward left. Resulting is *2 of the value by shifting value.

    like

    1<<3 will be 1*2*2*2=8, shifted 3 bits so three times *2


    "<<" indicates left shift (in binary numbers). So 1 << n is the same as 2 to the power of n. However it is most appropriate to look at it in binary,

    1<<0 = 1b
    1<<1 = 10
    1<<2 = 100
    
    链接地址: http://www.djcxy.com/p/12572.html

    上一篇: <<什么意思在Javascript中

    下一篇: 什么是1 << 1的值? 如何计算它?