3.3.4Combinational Circuits

Subtractors

2,110 words10 min readdifficulty · medium

WHAT is a subtractor?

There are two kinds:

  • Half Subtractor (HS) — subtracts 2 bits, ignores incoming borrow.
  • Full Subtractor (FS) — subtracts 2 bits plus an incoming borrow-in BinB_{in}.

WHY borrow (not carry)?


Half Subtractor — derive from scratch

We compute ABA - B for single bits. Enumerate all cases (this is Feynman-level honesty — never guess a truth table, build it):

AA BB ABA-B DD (diff) BoutB_{out} (borrow)
0 0 0 0 0
0 1 1-1 → borrow, result 11 1 1
1 0 1 1 0
1 1 0 0 0

Why row 2? 010-1 can't be 1-1 in an unsigned column, so we borrow 22: 0+21=10+2-1 = 1 gives D=1D=1, and we mark Bout=1B_{out}=1 because we took from above.

Now read the columns as boolean functions:

  • D=1D=1 when exactly one input is 1 → that's XOR.
  • Bout=1B_{out}=1 only in the row A=0,B=1A=0,B=1 → that's AˉB\bar{A}\cdot B.

Full Subtractor — derive from scratch

Now include a borrow coming in from the previous (lower) column, BinB_{in}. We compute ABBinA - B - B_{in}.

AA BB BinB_{in} ABBinA-B-B_{in} DD BoutB_{out}
0 0 0 0 0 0
0 0 1 1-1 1 1
0 1 0 1-1 1 1
0 1 1 2-2 0 1
1 0 0 1 1 0
1 0 1 0 0 0
1 1 0 0 0 0
1 1 1 1-1 1 1

Why the DD column is XOR of three? The difference bit is 1 whenever an odd number of the three inputs are 1 (check: rows with 1,1,1 or a single 1 give D=1D=1). Odd-parity of three bits is three-input XOR.

D=ABBinD = A \oplus B \oplus B_{in}

Deriving BoutB_{out} algebraically (this mirrors the full-adder carry derivation). Group the Bout=1B_{out}=1 rows using the two-stage idea. Do the subtraction as two half-subtracts:

  1. First ABA-B: produces intermediate diff d1=ABd_1=A\oplus B and borrow b1=AˉBb_1=\bar A B.
  2. Then d1Bind_1 - B_{in}: produces final D=d1BinD=d_1\oplus B_{in} and borrow b2=d1Binb_2=\overline{d_1}\,B_{in}.
  3. A borrow is needed overall if either subtract borrowed: Bout=b1+b2B_{out}=b_1+b_2.

Bout=AˉB+(AB)BinB_{out} = \bar A B + \overline{(A\oplus B)}\,B_{in}

Simplify AB=AB+AˉBˉ\overline{A\oplus B} = AB + \bar A\bar B, so: Bout=AˉB+(AB+AˉBˉ)BinB_{out} = \bar A B + (AB+\bar A\bar B)B_{in}

A neater standard SOP form (verify from the truth table) is:

Figure — Subtractors

The 80/20 shortcut: subtraction = addition of 2's complement

AB=A+B+1(mod2n)A - B = A + \overline{B} + 1 \pmod{2^n}

WHY it works: 2's complement of BB is 2nB2^n - B, so A+(2nB)=2n+(AB)A + (2^n - B) = 2^n + (A-B). The 2n2^n is just the carry-out you discard, leaving ABA-B.


Worked examples


Common mistakes


Forecast-then-Verify

Recall Predict before peeking

Q: For FS with A=1,B=0,Bin=1A=1,B=0,B_{in}=1, what are DD and BoutB_{out}? Forecast: 101=01-0-1=0, no borrow. Verify: D=101=0D=1\oplus0\oplus1=0 ✓, Bout=1ˉ0+1ˉ1+01=0B_{out}=\bar1\cdot0+\bar1\cdot1+0\cdot1=0 ✓.


Recall Feynman: explain to a 12-year-old

Imagine you have candies in stacked jars. Top jar has some, bottom jar has some, and you must take the bottom amount away from the top. If the top jar doesn't have enough, you run upstairs and borrow one big bundle (worth 2 candies in binary) from the next jar up — but now that upper jar owes one back, and that "owes one" note is the borrow-out. The difference bit is just whatever candies are left in the current jar. That's all a subtractor does: leftover candies (difference) and the "I owe upstairs" note (borrow).


Connections

  • Adders — subtractor shares D=D= Sum == XOR; borrow mirrors carry with an inverted AA.
  • Twos-Complement-Representation — basis of AB=A+Bˉ+1A-B=A+\bar B+1.
  • Adder-Subtractor-Circuit — one XOR-controlled unit does both.
  • XOR-Gate — parity behaviour behind the difference bit.
  • Ripple-Carry-Chains — cascading FS for multi-bit subtraction.

Flashcards

Half subtractor difference expression
D=ABD = A \oplus B
Half subtractor borrow expression
Bout=AˉBB_{out} = \bar A B
Why is half-subtractor borrow AˉB\bar A B not ABAB?
You borrow only when top bit A=0A=0 and bottom bit B=1B=1.
Full subtractor difference expression
D=ABBinD = A \oplus B \oplus B_{in}
Full subtractor borrow expression
Bout=AˉB+AˉBin+BBinB_{out} = \bar A B + \bar A B_{in} + B B_{in} (equivalently AˉB+(AB)Bin\bar A B + \overline{(A\oplus B)}B_{in})
Difference between adder-Sum and subtractor-Difference logic
None — both are XOR of the inputs.
How does full-subtractor borrow differ from full-adder carry?
Replace AA with Aˉ\bar A: Cout=AB+(AB)CinC_{out}=AB+(A\oplus B)C_{in} vs Bout=AˉB+(AB)BinB_{out}=\bar A B+\overline{(A\oplus B)}B_{in}.
How to compute ABA-B using an adder?
A+Bˉ+1A + \bar B + 1 (invert B, set carry-in to 1).
Why does 2's-complement subtraction work?
Bˉ+1=2nB\bar B+1 = 2^n-B, so A+2nB=2n+(AB)A+2^n-B=2^n+(A-B); discard the 2n2^n carry.
In multi-bit subtraction, what does the final borrow-out mean?
If 1, the result is negative (A<BA<B); if 0, ABA\ge B.
For FS row A=0,B=1,Bin=1A=0,B=1,B_{in}=1, give D,BoutD,B_{out}.
D=0D=0, Bout=1B_{out}=1 (subtracting 011=20-1-1=-2).
What makes DD a 3-input XOR in the full subtractor?
Difference is 1 exactly when an odd number of the three inputs are 1 (odd parity).

Concept Map

computes

computes

mirror of

uses carry vs

two kinds

two kinds

ignores

includes

diff is

borrow is

diff is

from

truth table

truth table

Subtractor

Difference D

Borrow Bout

Adder

Half Subtractor

Full Subtractor

Borrow-in Bin

D equals A XOR B

Bout equals notA and B

D equals A XOR B XOR Bin

Odd parity of 3 bits

Enumerated cases

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, subtractor basically adder ka ulta bhai hai. Jaise addition mein hum "carry" upar bhejte hain, waise hi subtraction mein jab upar wala digit chhota ho jaye to hum next column se "borrow" karte hain — school wala ghatana yaad karo, jab 535-3 mein upar se ek udhaar leke aate the. Yehi udhaar hardware mein borrow bit ban jaata hai. Half subtractor sirf do bits ABA-B karta hai: difference D=ABD=A\oplus B (bilkul adder ke sum jaisa), aur borrow Bout=AˉBB_{out}=\bar A B — yani borrow tabhi hota hai jab top bit A=0A=0 ho aur B=1B=1 ho.

Sabse common galti yehi hai ki log borrow ko ABAB likh dete hain, kyunki adder ka carry ABAB hota hai aur diff toh same XOR hai. Par bhai, borrow ke liye top bit ka broke hona zaroori hai (yani A=0A=0), isliye bar AA ke upar lagta hai: AˉB\bar A B. Row A=0,B=1A=0, B=1 ko hamesha check karke confirm karo.

Full subtractor mein ek extra BinB_{in} (pichle column se aaya udhaar) aata hai. Difference ban jaata hai teen-input XOR: D=ABBinD=A\oplus B\oplus B_{in}, aur borrow Bout=AˉB+(AB)BinB_{out}=\bar A B+\overline{(A\oplus B)}B_{in} — full adder ke carry jaisa hi skeleton, bas AA pe bar lag gaya.

Asli maza yeh hai: real processors alag subtractor banate hi nahi. Wo 2's complement trick use karte hain — AB=A+Bˉ+1A-B = A+\bar B+1. Matlab BB ke saare bits invert karo aur adder ka carry-in 11 set kar do. Ek control line se ek hi circuit adder bhi aur subtractor bhi ban jaata hai. Yeh 80/20 point hai — isko pakka yaad rakho, exam aur real design dono mein kaam aayega.

Go deeper — visual, from zero

Test yourself — Combinational Circuits

Connections