Skip to main content
4 of 4
edited tags
CharlesB
  • 91.5k
  • 29
  • 203
  • 228

Two's complement binary form

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.

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?

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

paragjain
  • 275
  • 1
  • 5
  • 12
lang-cpp