Unsigned Subtraction in Modern Computers: Exploring the Method of Complements

  • Thread starter adjacent
  • Start date
  • Tags
    subtracting
In summary, modern computers do not have dedicated circuits for subtraction and instead use the method of complements. For 2's complement numbers, the result of addition will be another 2's complement which, when interpreted as a 2's complement number, will give the correct result as long as there is no overflow. In the case of a 4-bit number, the unsigned range is 0 to 15 and the signed range is -8 to 7. When computing 15u - 14u, the first thought may be to do the 2's complement of 14 and add it to 15, but this does not work since -14 is not in the range of a 4-bit number. However, flipping
  • #1
adjacent
Gold Member
1,552
63
Modern computers don't have circuits dedicated for subtraction. They do it by using the method of complements.

All is well when the 2 operands are signed 2's complement numbers. The result of addition will be another 2's complement which, when interpreted as a 2's complement number, will give the correct result provided that there's no overflow.

Consider a 4 bit number. The unsigned range is 0 <-> 15. Signed range is -8 <-> 7.

What happens when I do 15u - 14u? The first thought which comes is "Do the 2's complement of 14 and do 15 + (-14)". But then, -14 is not in the range of a 4 bit number.

But if I do it anyway (Flip all bits and add 1):
Code:
  1111
+ 0010
------------
1  0001  =  0001 4 bits
It seems to work. My problem is that 0010 is not equal to -14 in 2's complement. It's just 2.

Question: Why does it work? And is this even the actual way it's happening?
 
Technology news on Phys.org
  • #2
adjacent said:
It seems to work. My problem is that 0010 is not equal to -14 in 2's complement. It's just 2.
0010 is the 2's complement representation of -14, working with 4-bit numbers.
You can convince yourself of this by adding 1110 (the 4-bit representation of 14) and 0010 (the 4-bit 2's complement representation of -14). You should end up with 1 0000, with the lower 4 bits being all zero.
adjacent said:
Question: Why does it work? And is this even the actual way it's happening?
 
  • Like
Likes adjacent
  • #3
Mark44 said:
0010 is the 2's complement representation of -14, working with 4-bit numbers.
You can convince yourself of this by adding 1110 (the 4-bit representation of 14) and 0010 (the 4-bit 2's complement representation of -14). You should end up with 1 0000, with the lower 4 bits being all zero.
If the range of 4 bit signed is -8 <-> 7, how come -14 fit in there?
Or would it be more wise to call it modular additive inverse instead which happens to be same as 2's complement for unsigned numbers? It actually makes more sense.
 
  • #4
adjacent said:
If the range of 4 bit signed is -8 <-> 7, how come -14 fit in there?
You're right -- -14 is not in that interval. What I said was applicable for 5 or more bits, not 4.
adjacent said:
Or would it be more wise to call it modular additive inverse instead which happens to be same as 2's complement for unsigned numbers? It actually makes more sense.
 
  • #5
Mark44 said:
What I said was applicable for 5 or more bits, not 4.
I'm not sure what you mean now. Could you elaborate?
What exactly is it for 4 bits? 2's complement or modular additive inverse?
 
  • #6
For an unsigned 4-bit number, the range is 0 through 15. For a signed 4-bit number, the range, as you know, is -8 through 7, so neither 14 nor -14 is in that range.

With regard to a processor with 4-bit registers, I suspect that what happens when 15 - 14 is computed:
1. 15 - 14 is interpreted as 15 + (-14)
2. -14 is converted to its 2's complement form, or 0010
3. 15 - 14 is interpreted as 1111 + 0010, which results in 0001, which is the correct answer.
 
  • Like
Likes adjacent

1. What is unsigned subtraction in modern computers?

Unsigned subtraction in modern computers is a mathematical operation used to find the difference between two unsigned numbers. It is a method that involves taking the complement of the subtrahend (the number being subtracted) and adding it to the minuend (the number being subtracted from), resulting in the difference.

2. How is the method of complements used in unsigned subtraction?

The method of complements is used in unsigned subtraction by taking the complement of the subtrahend and adding it to the minuend. This is done by first finding the complement of the subtrahend, which involves flipping all the bits (0s to 1s and 1s to 0s) and adding 1. Then, this complement is added to the minuend using binary addition, resulting in the difference.

3. What are the advantages of using the method of complements in unsigned subtraction?

The method of complements has several advantages in unsigned subtraction, including:

  • It simplifies the subtraction process, as it only involves addition and no borrowing.
  • It is faster and more efficient for computers to perform than traditional subtraction methods.
  • It allows for a wider range of numbers to be subtracted, including negative numbers.

4. Are there any limitations to using the method of complements in unsigned subtraction?

Yes, there are some limitations to using the method of complements in unsigned subtraction. One limitation is that it does not work for signed numbers, as it can result in incorrect differences. Additionally, it can be more difficult for humans to understand and perform compared to traditional subtraction methods.

5. How is the method of complements related to two's complement notation?

The method of complements is closely related to two's complement notation. In both methods, the complement of a number is used to represent the negative version of that number. However, in two's complement notation, the complement is found by subtracting the number from a power of 2, while in the method of complements, the complement is found by flipping the bits and adding 1. Both methods are commonly used in computer systems to represent and perform operations on negative numbers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
624
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
32
Views
1K
  • Programming and Computer Science
Replies
1
Views
5K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
950
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top