Are the shift operators (<<, >>) arithmetic or logical in C?

后端 未结 11 1601
粉色の甜心
粉色の甜心 2020-11-22 07:52

In C, are the shift operators (<<, >>) arithmetic or logical?

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 08:35

    When you do - left shift by 1 you multiply by 2 - right shift by 1 you divide by 2

     x = 5
     x >> 1
     x = 2 ( x=5/2)
    
     x = 5
     x << 1
     x = 10 (x=5*2)
    

提交回复
热议问题