bit-manipulationbittwos-complementcomplement

2s Complement of a negative zero


I have problem: you know the 2s Complement so you can get the negative number of a positive one with the reverse and adding a one. e.g.

8 Bit
121 = 0111 1001
 1st= 1000 0110
  +   0000 0001
      ---------
      1000 0111 --> -121 

So now if we have a -0

a zero looks as 8 bit

0000 0000

so a minus 0 should look

 1111 1111 + 0000 0001
= 10000 0000

but that is 512

so I think that I've misunderstood something


Solution

  • 1 0000 0000b is 256, not 512. Truncated to 8 bits, it's 0.

    This is because with two's complement, zero is zero. There is no positive or negative zero.

    Compare this to one's complement or sign bit, where positive zero and negative zero are different values.