← Binary Course — Part C, lesson 4 of 5 (Negative numbers)

12. Two's Complement Arithmetic: Subtraction Without a Subtract Circuit

LESSON 12 | 0000 1100 | 0x0c

The concept

Lesson 11 gave two's complement addition one plain rule for every combination of signs: add the two 8-bit patterns, and if that produces a 9th bit, discard it — the correct answer just falls out, no branching on which operand is bigger or which sign is which.

Subtraction needs nothing new on top of that. a - b is computed as a + (-b): negate b using Lesson 11's invert-then-add-1 method, then add the result to a using the exact same plain-add-and-discard-the- overflow rule Lesson 11 already established. That's the whole method — subtraction isn't a second operation at all, just Lesson 11's negation composed with Lesson 11's addition, both already built.

This is the other half of why real hardware settled on two's complement. Lesson 11 already noted that subtraction reduces to "invert and add," so the same adder circuit serves both operations. Stated the other way around: a machine that can invert bits (Lesson 5's NOT) and add never needs a distinct subtract circuit or a distinct subtract algorithm at all — every subtraction is just an addition wearing a negated operand.

One case is worth flagging before the examples: subtracting a negative number. a - (-b) means negating -b — and negating an already-negative two's-complement value flips it back to positive (Lesson 11 Example 1's invert-then-add-1, run on a negative input this time), so a - (-b) becomes a + b. That matches the ordinary arithmetic rule "subtracting a negative is the same as adding," but here it isn't a separate rule to remember — it's the same invert-then-add-1 step from Lesson 11, applied to whichever operand follows the minus sign, positive or negative.

Example 1 — Subtracting a smaller positive: 9 - 3

Negate 3 the Lesson 11 way (+3 = 0000 0011):

invert 0000 0011  ->  1111 1100
add 1             ->  1111 1101   (-3)

Now add +9 and -3 using Lesson 11's addition rule:

0000 1001   (+9)
  • 1111 1101 (-3)

1 0000 0110 <- a 9th bit, discarded exactly like Lesson 11's additions

Discarding the 9th bit leaves 0000 0110 = 6 — correct (9 - 3 = 6), produced entirely by negating 3 and then reusing Lesson 11's plain-add rule.

Example 2 — Subtracting a larger positive: 3 - 9

Negate 9 (+9 = 0000 1001):

invert 0000 1001  ->  1111 0110
add 1             ->  1111 0111   (-9)

Add +3 and -9:

0000 0011   (+3)
  • 1111 0111 (-9)

1111 1010   <- no 9th bit this time

No carry was produced, so there's nothing to discard — the plain sum is already the answer. Decoding it (sign bit 1, so invert and add 1 to recover the magnitude: invert(1111 1010) = 0000 0101, +1 = 0000 0110 = 6) gives -6 — correct (3 - 9 = -6). Same negate-then-add method as Example 1, no separate case needed for a negative result.

Example 3 — Subtracting a negative: 5 - (-3)

5 - (-3) means negating -3 itself. -3 (from Example 1) is 1111 1101:

invert 1111 1101  ->  0000 0010
add 1             ->  0000 0011   (= +3)

Negating a negative value flipped it back to +3 — exactly Lesson 11 Example 1's invert-then-add-1 step, just applied starting from a negative pattern instead of a positive one. Now add +5 and this +3:

0000 0101   (+5)
  • 0000 0011 (+3)

0000 1000   <- no 9th bit

0000 1000 = 8 — correct (5 - (-3) = 5 + 3 = 8). "Subtracting a negative" needed no new rule at all; it fell straight out of negating whatever follows the minus sign, the same as every other case.

Example 4 — Two negatives: -5 - (-3)

Negating -3 again gives +3 = 0000 0011, same as Example 3. Add it to -5 (1111 1011, from Lesson 11):

1111 1011   (-5)
  • 0000 0011 (+3)

1111 1110   <- no 9th bit

Decoding 1111 1110 (invert, then add 1: invert = 0000 0001, +1 = 0000 0010 = 2) gives -2 — correct (-5 - (-3) = -5 + 3 = -2). Four examples, four different sign combinations of a and b, and every one used the identical two steps: negate b, then add using Lesson 11's rule. No dedicated subtraction algorithm ever entered the picture.

Exercises

Exercise 1. Compute 19 - 7 in 8-bit two's complement: negate 7 using invert-then-add-1, then add the result to 19 using Lesson 11's addition rule.

Exercise 2. Compute 7 - 19 the same way, then give the 8-bit result in hex using Lesson 3's nibble table.

Exercise 3. A classmate, in a hurry, computes 9 - 3 (Example 1) by just adding the two patterns for 9 and 3 directly — 0000 1001 + 0000 0011 — without negating 3 first. What word do they get, what does it decode to, and why is that wrong? What step did they skip?

Show Answer Key

1. +19 = 0001 0011. Negate 7 (0000 0111): invert -> 1111 1000, add 1 -> 1111 1001 (-7). Add: 0001 0011 + 1111 1001 = 1 0000 1100 (9 bits) — discard the 9th bit, leaving 0000 1100 = 12. Correct: 19 - 7 = 12.

2. +7 = 0000 0111. Negate 19 (0001 0011): invert -> 1110 1100, add 1 -> 1110 1101 (-19, matching Lesson 11 Exercise 1's answer). Add: 0000 0111 + 1110 1101 = 1111 0100 — no 9th bit produced this time, so nothing to discard. Decoding (sign bit 1: invert -> 0000 1011, add 1 -> 0000 1100 = 12) gives -12, correct (7 - 19 = -12). In hex (Lesson 3): 1111 -> f, 0100 -> 4, so 0xf4.

3. Adding the patterns directly, without negating 3 first, is just 0000 1001 + 0000 0011 = 0000 1100 = 12 — no carry produced, so nothing even looks unusual about the arithmetic itself. But 12 is 9 + 3, not 9 - 3; the correct answer, from Example 1, is 6. The skipped step is the negation: subtracting b always means negating b first and adding the result, never adding the raw, unnegated pattern for b. Skip that step and every subtraction silently turns into the wrong addition instead — one more reason a - b is never a separate operation to learn, just a reminder to negate before reusing Lesson 11's addition rule.

Every example and exercise here happened to produce a result that fits comfortably in 8 bits. Lesson 13 covers what happens when it doesn't — overflow, the case where the true mathematical answer falls outside what an 8-bit two's-complement word can represent at all, and how to detect that it happened.