1

assume: 2's compliment, integer. just a quick question. why is it that If a had a number, and take the NOT of it, that it will equal negative +or- 1. for example:

553481923
~553481923 = -553481924
2147455726
~2147455726 = -2147455727
-2147455725
~-2147455725 =2147455724

I understand that the bits are inverted. is there any reason for this happening, or is this just coincidence.

dgamma3
  • 2,333
  • 4
  • 26
  • 47

2 Answers2

0

This is because of the way 2's complement notation works.

The range of 2's complement integer is (-2^31) to (2^31 - 1)

Take for example the 2's complement 8 bit value:

0000 0000 = 0 (base 10)

and the 2's complement negative 8 bit value:

1111 1111 = -1 (base 10)
AdnanEK
  • 198
  • 1
  • 4
  • 13
0

That is because you can express one additional negative value in a 2's complement system, because 00000000 is zero. That means that out of all of the positive numbers which you can express (up to 01111111), you will still be shorted that one extra bit. On the other hand, you get 10000000 as a negative number. (I have been using bytes, but this applies to words of any length.)

https://stackoverflow.com/a/1049774/691859

Community
  • 1
  • 1
2rs2ts
  • 10,662
  • 10
  • 51
  • 95