Hi,
There is another interesting method for obtaining the two's complement. I found this most interesting because in part it is another example of how things in binary can simplify.
The old way is like this:
Start with the number say: 01001000
Negate each bit: 10110111.
Add 1 to the result: 10111000
Done.
The new way:
Start with the number: 01001000.
Look at each bit from right to left, any bit that is zero leave alone until you reach the first non zero, and leave that single non zero bit (1) alone also, so the last four bits are: 1000 and these get left alone, and the remaining four bits are 0100.
Now invert the remaining bits: 1011
Now put the number back together: 10111000
Done.
Note the result is the same as before.
The benefit seems to be that we never have to add, which can result in a ripple carry that could take a long time to calculate, and so we have to deal with each bit one time only no matter how many bits we have.
The 0000 example is even simpler, because it's all zeros, so all those zeros stay the same.
An example like this: 1000101
is also interesting, because we have no zeros on the far right, so everything to the left of the first 1 simply gets negated: 0111011
Lets check it:
1000101 negated: 0111010, add 1: 0111011
same result.
Also, an example like this: 1000 0000 0000 0000 (this is 16 bits)
becomes: 1000 0000 0000 0000
because we leave all the zeros and the first '1' encountered alone.
Lets check this one:
1000 0000 0000 0000 negated becomes 0111 1111 1111 1111,
and now to add 1 we have to ripple carry over all the digits from right to left when adding 1 to get: 1000 0000 0000 0000
The simplification in calculating the 2's complement starts to become clear.
Pretty interesting!