Can anyone explain why '>>2' shift means 'divided by 4' in C codes?

后端 未结 10 1430
谎友^
谎友^ 2020-12-05 09:25

I know and understand the result.

For example:


7 (decimal) = 00000111 (binary)
and 7 >> 2 = 00000001 (binary)
10条回答
  •  [愿得一人]
    2020-12-05 09:33

    It's because >> and << operators are shifting the binary data.

    Binary value 1000 is the double  of binary value 0100
    Binary value 0010 is the quarter of binary value 1000
    

提交回复
热议问题