二进制补码形式

二进制补码形式

问题描述:

在TC ++编译器中, 5 的二进制表示形式是(00000000000000101). 我知道负数存储为2的补数,因此二进制中的 -5 (111111111111011).最高有效位(符号位)为1,表示它是负数.

In a TC++ compiler, the binary representation of 5 is (00000000000000101). I know that negative numbers are stored as 2's complement, thus -5 in binary is (111111111111011). The most significant bit (sign bit) is 1 which tells that it is a negative number.

那么编译器如何知道它是 -5 ?如果我们将(111111111111011)上面给出的二进制值解释为无符号数字,结果会完全不同吗?

So how does the compiler know that it is -5? If we interpret the binary value given above (111111111111011) as an unsigned number, it will turn out completely different?

还有,为什么1表示 5 -6(1111111111111010)?

Also, why is the 1's compliment of 5 -6 (1111111111111010)?

编译器不知道.如果将-5强制转换为unsigned int,则会得到32763.

The compiler doesn't know. If you cast -5 to unsigned int you'll get 32763.