[Math] Subtracting Binary Numbers with one and two’s complement

binary

An example:

$01001 – 11010 = -10001 = -17$

one's complement: $00101$
two's complement: $00110$

so the above statement should evaluate the same as:

$01001 + 00101 = 01110$ (inverting it) $= 10001$ which is almost the same except $+17$ rather than $-17$ so I use the first bit as a sign bit then its just $-1.$

using the two's complement is not much better:

$01001 + 00110 = 01111 = 15$ which again is nowhere near the $-17$.

What in the world am I doing wrong$?$ This seems so simple but I can't get it to work.

Best Answer

I always manage to confuse myself with this process since it is not done manually too often, so refer to this handy algorithmic like approach. In both cases, the number we are subtracting is larger in magnitude.

$1's$ Complement:

  1. Determine the $1's$ complement of the larger number: $00101$
  2. Add the $1's$ complement to the smaller number: $01001 + 00101 = 01110$
  3. There is no carry. The result has the opposite sign from the answer and is the $1's$ complement of the answer.
  4. Change the sign and take the $1's$ complement of the result to get the final answer: $-10001$

This is $-17$.

$2's$ Complement:

  1. Determine the $2's$ complement of the larger number: $00110$
  2. Add the $2's$ complement to the smaller number: $01001 + 00110 = 01111$
  3. There is no carry from the left-most column. The result is in $2's$ complement form and is negative.
  4. Change the sign and take the $2's$ complement of the result to get the final answer: $-10001$

This is $-17$.