assemblycpu-architecturedigital-logic

Using One's Complement In Place of Directly Subtracting Two Binary Numbers


I've decided to start learning some logic design recently. I'm current at the very first unit in the book I'm using (Fundamentals of Logic Design - 5th Edition if it's of any importance) and it's given me a series of questions to answer. Prior to the actual question, it gave me the following: A - B = A + (-B). Add the complement of a number with a regular number in place of actually subtracting those numbers directly.

I've gotten to a question where it's asking me to subtract 10110 (22) with 01101 (13) by adding 10110 (22) and the 1's complement of 01101 (10010) together. You'd assume that the answer would be 1001 (9), right? I did just that and did get 01001, but the solutions section of the book I'm using state that there is an overflow. I've even checked another version of the solutions section online, but it's still stated as an overflow. I just want to know why the book stated that this would result in an overflow, but still have the binary representation of the output be correct.

The solution from the book solution section

The solution from the book solution section

I'm still new with this whole logic design stuff. 1's and 2's complement did get me a bit hung up. Help would be appreciated.


Solution

  • I just want to know why the book stated that this would result in an overflow ...

    I can imagine two things:

    1. The book wants you to keep in mind that when using one's complement, you have to add one to the result if there is a carry-out from the highest bit:

      10110 + 10010 = (1)01000 = 01000 + 1

    2. The result is not really correct:

      If you are really calculating with 5-bit numbers (and not with 6-bit numbers), 10110 is not 22 but it is (-9)!

      You need at least 6 bits for the value 22.

      (So the values in the question were already wrong!)

      However, (-9)-13 is (-22) and not 9!

      Because you need at least 6 bits for the value (-22), you cannot get the correct result if you are calculating with 5 bits.