1

For my computer science class I need to finish a project where I desperately need to understand logic of one's complement and two's complement. I already know how to construct these and also how hardware adder works when dealing with two's complement. The thing that is bothering me and I need help with is the logic behind one's complement addition. Why do we have to add the bit we would carry over (and discard when using two's complement coding) to the sum to get the correct result? I don't understand why binary addition behaves like this when adding one's complement and why is that last adding of carry over bit so crucial. I need to understand the logic behind it. Thanks

David Richerby
  • 81,689
  • 26
  • 141
  • 235
fifco
  • 11
  • 2

1 Answers1

4

A binary number in one's complement is represented by $\bar{N} = (2^{n} - 1) - N$.
So when you subtract N from M you get: $$ S = M - N = M + \bar{N} = M + (2^{n} - 1 - N) = (M - N) + 2^{n} - 1 $$ And when you do the so called end-around carry operation you effectively add $-2^{n}+1$ to the intermediate result because you take away the MSB and add 1. So you get:
$$SUM = S -2^{n}+1= (M - N) + 2^{n} - 1 - 2^{n}+ 1 = M - N$$ This is correct again.

In two's complement ($2^{n} - N$) you have: $$S = -M + N = \bar{M} + N = (2^{n} - M) + N = 2^{n} - (N - M)$$ Discarding the MSB does $- 2^{n}$ and gives you: $$SUM = S -2^{n} = 2^{n} - (N - M) - 2^{n} = N - M$$

Done you are.

Benjoyo
  • 506
  • 4
  • 13