How Does Unsigned Subtraction Work in Modern Computers Using Complements?

  • Thread starter Thread starter adjacent
  • Start date Start date
  • Tags Tags
    subtracting
Click For Summary

Discussion Overview

The discussion centers on the method of unsigned subtraction in modern computers using complements, specifically focusing on how subtraction is performed with 4-bit numbers and the implications of using 2's complement representation. Participants explore the mechanics of this process and the validity of certain representations.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant states that modern computers use complements for subtraction, noting that this works well for signed 2's complement numbers without overflow.
  • Another participant questions the validity of using 2's complement for unsigned numbers, specifically when calculating 15u - 14u, and expresses confusion about the representation of -14 in a 4-bit system.
  • A participant asserts that 0010 is the 2's complement representation of -14, but another counters that -14 does not fit within the signed range of a 4-bit number.
  • There is a suggestion that it may be more appropriate to refer to the concept as a modular additive inverse rather than strictly 2's complement for unsigned numbers.
  • One participant clarifies that the previous statements about -14 were applicable to 5 or more bits, not 4 bits, prompting further inquiry about the correct interpretation for 4-bit numbers.
  • A participant outlines a step-by-step process of how subtraction is computed in a 4-bit register, emphasizing the interpretation of -14 and its conversion to 2's complement.

Areas of Agreement / Disagreement

Participants express disagreement regarding the representation of -14 in a 4-bit system, with some asserting it is valid in 2's complement while others argue it is not. The discussion remains unresolved, with multiple competing views on the interpretation of subtraction in this context.

Contextual Notes

Limitations include the ambiguity surrounding the representation of negative numbers in a limited bit-width system and the potential confusion between 2's complement and modular additive inverse concepts.

adjacent
Gold Member
Messages
1,552
Reaction score
62
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
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   Reactions: adjacent
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.
 
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.
 
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?
 
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   Reactions: adjacent

Similar threads

  • · Replies 1 ·
Replies
1
Views
899
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
1
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
13K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K