The difference between logical shift right, arithmetic shift right, and rotate right

前端 未结 3 1325
孤城傲影
孤城傲影 2020-12-04 22:08

I\'ve been reading the classic Hacker\'s delight and I am having trouble understanding the difference between logical shift right,arithmetic shift right, and rotate right. P

3条回答
  •  生来不讨喜
    2020-12-04 22:44

    Logical right shift means shifting the bits to the right and MSB(most significant bit) becomes 0.

    Example: Logical right shift of number 1 0 1 1 0 1 0 1 is 0 1 0 1 1 0 1 0.

    Arithmetic right shift means shifting the bits to the right and MSB(most significant bit) is same as in the original number.

    Example: Arithmetic right shift of number 1 0 1 1 0 1 0 1 is 1 1 0 1 1 0 1 0.

提交回复
热议问题