The way to find Two's Complement of a binary number is:
- Let x ̄ = the logical complement of x. The logical complement (also called the one’s complement) is formed by flipping all the bits in the number, changing all of the 1 bits to 0, and vice versa.
- Let X = x ̄ + 1. If this addition overflows, then the overflow bit is discarded. By the definition of two’s complement, X ≡ −x.
I have seen a quick way, which is:
eg.
B = 00010110 D = 22
Flip everything after the first "1" counting from left side.
-B = 11101010 -D = -22
I couldn't understand proof of this way.