3.3.9 · D3Combinational Circuits

Worked examples — Comparators

3,414 words16 min readBack to topic

Before anything, some words and symbols we will reuse. If you have not met them, read them slowly:


The scenario matrix

Every comparator problem lives in exactly one of these cells. Our examples below are labelled by cell so you can see the whole space is covered.

Cell What happens Which rule fires Example
C1 1-bit, all four rows raw Ex 1
C2 Multi-bit, MSB alone decides term Ex 2
C3 Multi-bit, MSBs tie → LSB decides guard Ex 3
C4 Full equality (every bit matches) Ex 4
C5 Extreme inequality all 0s vs all 1s (and the mirror all 1s vs all 0s) limiting case, both directions Ex 5
C6 The vs trap (MSB beats many low 1s) MSB-first proof Ex 6
C7 Degenerate guard — what if you forget ? contradiction demo Ex 7
C8 Cascaded 7485, local tie → pass-through Ex 8
C9 Cascaded, local decides → cascade ignored pass-through blocked Ex 9
C10 Word problem (threshold / real world) applied Ex 10

We will keep re-using the 2-bit equations from the parent (remember every "" here is OR):


Example 1 — the 1-bit engine, all four rows (Cell C1)

Figure — Comparators

Forecast: guess which single output is high for before reading on.

  1. Row . ; ; . So . Why this step? We must test the "both zero" degenerate case — equal numbers still count.
  2. Row . ; ; . So . Why? This is the only " smaller" 1-bit case; it must light exactly .
  3. Row . ; ; . So . Why? The forecast answer — , greater must fire alone.
  4. Row . ; ; . So . Why? This is the "both one" case — the second way two bits can be equal, so must fire just like row .

Verify: count how many outputs are high per row (this "" is an arithmetic count, not Boolean OR) — row : ; row : ; row : ; row : — every count is , so exactly one output fires each row. The law holds. ✔ (See Truth Tables and Minterms for reading these off.)


Example 2 — MSB alone decides (Cell C2)

Forecast: , so guess — but prove the LSB term never even gets a chance to speak.

Here ( are the MSBs; the LSBs).

  1. Guards. . . Why this step? is the whole story: the MSBs differ, so no lower term will be allowed through.
  2. Greater. (the "" here is OR). Why? First term fires from the MSB. The second term is multiplied by , so it is dead — exactly what we wanted.
  3. Less & Equal. . .

Verify: count of high outputs ✔. And ✔. The MSB decided; the LSB was irrelevant.

The figure below shows this exact case: the shaded region marks the LSB column that the guard switches off, and the orange arrow shows the MSB making the decision alone.

Figure — Comparators

Example 3 — MSBs tie, LSB breaks the tie (Cell C3)

Forecast: the top bits match, so the guard must open the gate and let the LSB decide. Guess the winner.

Here .

  1. Guards. (MSBs match — gate is open). . Why this step? is the permission slip that lets the LSB term act.
  2. Greater. . Why? First term is (MSBs equal, nobody wins there). Second term survives because , and says the LSB of beats .
  3. Less & Equal. . .

Verify: count of high outputs ✔; ✔. This is the pure LSB-tiebreak case — contrast it with Ex 2 where the LSB never mattered.

Compare the figure below with the one from Ex 2: here the MSBs match, so the guard opens the gate (no shaded dead column), and the orange arrow now points at the LSB column, which is where the decision actually happens.

Figure — Comparators

Example 4 — full equality (Cell C4)

Forecast: equal numbers — guess which single output is high and which two are zero.

  1. Guards. ; . Why this step? Both flags are — this is what "every bit matches" looks like numerically.
  2. Equal. . Why? Equality requires all guards high; the AND of them lights .
  3. Greater. . Why? and kill both greater-terms — no bit of is strictly above .
  4. Less. By the same mirror logic .

Verify: count of high outputs ✔; ✔. Equality is the AND-of-guards — remember XNOR, not XOR (see the trap in Ex 7).


Example 5 — the extreme inequality, both directions (Cell C5)

Forecast: the smallest vs the largest, then flipped. Guess which output fires in each, and whether the MSB alone settles it both times.

(a) .

  1. Guards. ; . Both gates shut. Why this step? Every bit differs — the guards confirm there is no tie anywhere.
  2. Less. . Why? The MSB term alone fires; disables the LSB term (which would also have said "less", but we never need it).
  3. Greater & Equal. . .

Verify (a): count of high outputs ✔; ✔.

(b) — the mirror.

  1. Guards. ; . Both gates shut again.
  2. Greater. . Why? Now the MSB of is above 's , so the top greater-term fires alone.
  3. Less & Equal. . .

Verify (b): count of high outputs ✔; ✔. Both extremes: only the MSB term does the work — a preview of the trap in Ex 6.


Example 6 — the vs trap (Cell C6)

Forecast: count the 1s if you like — then watch the MSB overrule the count entirely.

The 4-bit greater equation (from parent §3; every "" below is OR):

  1. Top guard. . Why this step? The MSBs differ. That single multiplies every lower term to zero — the low three 1s of are silenced before they can vote.
  2. First term. . So . Why? 's MSB is while 's is : magnitude is settled at the top digit, exactly like humans comparing vs .
  3. Cross-check Less. 's MSB term is , and every lower -term is guarded by → all dead → .

Verify: count of high outputs ✔; ✔. The "count the 1s" instinct is wrong — the highest differing bit rules. This is the LSB-first trap warned about in the parent's §6; contrast with a Ripple Carry Adder which genuinely goes LSB-first.


Example 7 — degenerate guard: what forgetting breaks (Cell C7)

Forecast: the true answer is , so should be and should be . Guess whether obeys.

Here .

  1. Correct (guarded). . . Why this step? (MSBs differ) correctly muzzles the LSB term. ✔.
  2. Correct . . So ✔ ().
  3. Broken . . Why this step? Without the guard, the LSB term fires even though the MSB already declared . Now and simultaneously.

Verify: count of high outputs — the sacred identity is violated (two outputs high at once is impossible). That impossible count is the machine screaming that the guard was dropped. Always guard lower terms with .


Example 8 — cascaded 7485, local tie passes through (Cell C8)

Forecast: , , so . Guess how the high chip, which sees only equal bits, still reports "greater".

  1. Low chip result. Its bits vs : MSB of nibble vs → low chip outputs . Why this step? The low nibble is where the numbers actually differ; it must produce the real decision, exactly like Ex 6.
  2. High chip locals. Its bits vs are all equal → . Why? is the "I couldn't decide, ask the chip below me" flag — the pass-through switch.
  3. Cascade wiring. The high chip's is wired to the low chip's . Apply the formula (the "" is OR): . Why? Because opened the pass-through, the low chip's verdict flows straight to the final output.

Verify: final ; and ✔. This is the human "first-differing-digit" rule scaled up to whole chips.

The figure below draws the two chips as boxes: the orange arrow is the cascade wire carrying the low chip's "", and the label on the high chip marks the open pass-through that lets that verdict flow to the final output.

Figure — Comparators

Example 9 — cascaded 7485, local chip decides, cascade blocked (Cell C9)

Forecast: , . The high nibble already differs. Guess whether the low chip's opinion matters at all.

  1. Low chip result. vs : low chip reports , so the handed into the high chip . Why this step? We deliberately make the low chip say "" to test whether the high chip wrongly listens.
  2. High chip locals. vs : first differing bit is bit-2 (value 4), where , and (bits are not all equal). Why? shuts the pass-through gate: it becomes the multiplier on the cascade term, so nothing from the lower chip can leak through.
  3. Cascade formula. . Why? The multiplier zeroes the cascade term, so the low chip's contrary "" is completely ignored. The high chip decided.

Verify: final ; and ✔ despite the low nibble screaming "less". MSB-nibble authority wins — the same principle as Ex 6, now across chips.


Example 10 — word problem: a temperature threshold (Cell C10)

Forecast: , threshold . Guess ON or OFF, then locate which bit triggers it.

4-bit greater (every "" is OR): .

Bits: , (bit 3 is the MSB, bit 0 the LSB).

  1. Guards from the top. , , . All three top bits match. Why this step? We scan MSB→LSB; matching bits keep the gates open so the decision slides down to the first differing bit.
  2. First difference at LSB. Bit 0: . The surviving term is . All higher terms are because where bits matched. Why? Only the lowest bit differs, and there , so the fully-guarded LSB term is the one that fires.
  3. Result. → fan ON.

Verify: ; and ✔. A single-bit difference at the very bottom, correctly propagated by three open guards, drives the real-world actuator. This is why the chain is not optional decoration — it is the whole comparison machine. (An alternate route: compute and check the sign — see Binary Subtraction.)


Recall

Recall Quick self-test on the scenarios

When MSBs differ, do lower-bit terms ever fire? ::: No — the guard kills them all. In Ex 6, why doesn't counting 1s work? ::: Magnitude is set by the highest differing bit, not the count of 1s. What impossible count reveals a dropped guard? ::: two outputs high at once, so counts to . In a cascaded 7485, what makes the cascade input ignored? ::: zeroes the pass-through term. What flag opens the pass-through to the lower chip? ::: (local bits all equal). Does the "bigger pattern wins" rule hold for signed numbers? ::: No — these comparators are unsigned; signed compare treats the MSB as a sign bit.


Connections