Binary presentation of negative integer in Java

后端 未结 5 2005
予麋鹿
予麋鹿 2020-12-03 22:30

Please, help me to understand binary presentation of negative integers.

For example we have 5. Binary presentation of 5 is 00000000.00000000.00000000.00000101

5条回答
  •  粉色の甜心
    2020-12-03 23:17

    With two's complement it's true that a MSB of 1 indicates a negative number. But the remaining bits are not the binary representation of its value. On the other hand, if the MSB is 0 the remaining bits represent the binary value. But it cannot be said that the number is positive then. Zero is neither positive nor negative.

    This picture helped me to understand the principle when I started to learn that there are more representations of numbers than with 0..9:

               0
        -1    000    1
           111   001  
    -2  110         010  2
           101   011
        -3    100    3
              -4
    

提交回复
热议问题