1

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.

user118494
  • 5,837

2 Answers2

1

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$.

Moo
  • 11,311
  • Thank you! I think what I was missing is that after you do everything you have to find the complement again to get the final answer. – user125621 Jan 15 '16 at 13:09
  • You are quite welcome and I also forget those little tidbits so like using approaches that are clearly mapped out. I would recommend trying example for various sizes that hit all combinations. – Moo Jan 15 '16 at 13:27
0

Binary format works:

2^^01001 - 2^^11010

-17