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

  • 1
    $\begingroup$ I'm not sure what you're asking. You have to do what you have to do, or you get the wrong answer. $\endgroup$ – David Richerby Feb 21 '15 at 19:23

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.