Difference between >>> and >>

前端 未结 7 1097
情歌与酒
情歌与酒 2020-11-22 07:13

What is the difference between >>> and >> operators in Java?

7条回答
  •  既然无缘
    2020-11-22 07:50

    The right shift logical operator (>>> N) shifts bits to the right by N positions, discarding the sign bit and padding the N left-most bits with 0's. For example:

    -1 (in 32-bit): 11111111111111111111111111111111
    

    after a >>> 1 operation becomes:

    2147483647: 01111111111111111111111111111111
    

    The right shift arithmetic operator (>> N) also shifts bits to the right by N positions, but preserves the sign bit and pads the N left-most bits with 1's. For example:

    -2 (in 32-bit): 11111111111111111111111111111110
    

    after a >> 1 operation becomes:

    -1: 11111111111111111111111111111111
    

提交回复
热议问题