0
votes

My book says that to get the two's-complement representation, to just flip the bits and add 1. Correct me if I am wrong but the binary representation of -1 would be:

1000 0001

The MSB 1 denotes the sign (1 being negative number) and the 1 at the very end is where the 1 comes from.

So when I flip the bits:

0111 1110

So why does my book say that the two's complement representation of -1 is 1111 1111? I assume I am messing up somewhere.

3
read your book carefullyWalter Tross

3 Answers

2
votes

The book has right. 1111 1111 is the representation of -1 in two's complement.

Try add one to 1111 1111. The result is:

  1111 1111 +
  0000 0001
  ---------
1 0000 0000

The "one" at the beginning of the result is the "carry bit". The result is your answer: 0. At first glance you would say that overflow has occurred, but not at this time, because the result (the zero) can be represented on 8 bits.

One more example:

If you add -1 to -1 then you should get -2:

  1111 1111 +
  1111 1111
  ---------
1 1111 1110

And so on...

0
votes

So why does my book say that the two's complement representation of -1 is 1111 1111?

It's because the MSB is negative and the rest is positive:

1111 1111 = -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 => -1
0
votes

If you flip the bits of 1111 1111 you would get 0000 0000 if you add one then its 0000 0001 = 1 but that would be -1. Conversely if you want to represent -1 then think of it in reverse. 1 is represented 0000 0001 subtract 1 => 0000 0000, then flip it => 1111 1111. And -2 from above. 2 => 0000 0010. Subtract 1 => 0000 0001, flip it => 1111 1110.