Maker Pro
Maker Pro

Doubt in two's complement

KrisBlueNZ

Sadly passed away in 2015
The extra '1' you added at the start is the carry bit; it is not part of the result.

The one's complement of 000 is 111. If you add 001 to 111, you get 000 with a carry.

You need to use a consistent bit width. If you allow your answer to be four bits wide, as in the example of adding 001 to 111 and getting 1000, then the number you're adding 001 to is not the one's complement of 0. The one's complement of 0 in a 3-bit system is 111, but in a 4-bit system, it's 1111. Add 0001 to that, and your result is 0000 with carry. No matter how many bits you use, the one's complement of 0 has all bits set; if you add 1 to that, your result will always be 0 with carry.

In 8-bit arithmetic, for example, the one's complement of 0 is 1111 1111. Add 0000 0001 to that, and you get 0000 0000 with a carry. The carry is not part of the result value because it doesn't fit into the number of bits that are being used for the addition.

In a signed integer system, the highest-order bit is the "negative" flag bit. In an 8-bit system, any number 0xxx xxxx is positive (or at least non-negative), and any number 1xxx xxxx is negative. The one's complement of 0 is "-1" which in an 8-bit system is 1111 1111. Adding 1 to -1 gives a result of 0 with a carry.
 
Thanks i got you.Its not the part of the value, it is the carry.That is that magic statement that cleared my doubt
 
Top