Exercises — Comparators
Before we start, one figure fixes the vocabulary so nothing below is a surprise.

Recall the tools you'll reuse everywhere:
- means "NOT " — flip the bit (, ).
- is an AND — it is only when and .
- is XOR — when the two bits differ.
- is XNOR — the "bit matches" flag, when .
Level 1 — Recognition
L1.1
State the three outputs of a comparator and the one identity that always ties them together.
Recall Solution
The outputs are ==== (), ==== (), and ==== (). Exactly one is high at any instant, so What this means: the three signals partition every possible input — there is no fourth case, and no two can be true at once.
L1.2
Fill the missing outputs in this 1-bit comparator truth table.
| 0 | 0 | ? | ? | ? |
| 0 | 1 | ? | ? | ? |
| 1 | 0 | ? | ? | ? |
| 1 | 1 | ? | ? | ? |
Recall Solution
| 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
Why: read each row as a number comparison. → . → . → . → . Notice every row has exactly one — that is in action.
L1.3
Which single gate implements 1-bit equality, and why is it not XOR?
Recall Solution
Equality is XNOR: . XOR outputs when the bits differ, which is the opposite of equal. Negating XOR gives "no difference" = equal. See XOR and XNOR Gates.
Level 2 — Application
L2.1
Using the 1-bit equations , , , evaluate all three outputs for .
Recall Solution
- .
- .
- .
So : , correct since . Sum . ✔
L2.2
For the 2-bit comparator use Evaluate for , .
Recall Solution
Here and .
- First term: .
- Because the first term is already , regardless of the second term.
Decimal check: , , indeed , so . ✔ The MSB alone settled it — exactly the "MSB rules" idea.
L2.3
Same 2-bit comparator. Evaluate , , for , using
Recall Solution
, .
- (MSBs match).
- (LSBs match).
- .
- term 1: ; term 2: → .
- term 1: ; term 2: → .
: equal. Decimal: . ✔
Level 3 — Analysis
L3.1
A student proposes the 2-bit design (no guard). Find an input where it produces two contradictory outputs, and explain the failure.
Recall Solution
Take , (so , ; truth is ).
- Correct : → . Good.
- Buggy .
The buggy circuit reports and simultaneously — it claims and . The unguarded LSB term fired even though the MSB already ruled . This violates . The guard exists precisely to silence lower bits once a higher bit has decided.
L3.2
Explain, using the "first differing bit" rule, why even though every low bit of the right number is .
Recall Solution
Scan from the MSB (bit 3) down, stopping at the first position where the two numbers differ.
- Bit 3: , . They differ here, at the very top.
- Rule: at the highest differing bit, ⇒ , and nothing below matters.
The three s in live in bits 2,1,0 — all less significant than the decision. Their combined weight is , but bit 3 alone is worth . So . This is why comparators scan MSB-first, unlike a Ripple Carry Adder which propagates carries LSB-first.
L3.3
Show algebraically that the 1-bit comparator satisfies for all four inputs.
Recall Solution
. Expand XNOR: . So the sum is Group by and : Every one of the four minterms appears exactly once, which is the whole truth-table space — so the sum is a tautology. See Truth Tables and Minterms.
Level 4 — Synthesis
L4.1
Design a 3-bit greater-than expression for vs from scratch, using the chain.
Recall Solution
Per-bit equality flags: , . The first differing bit (from the top) with decides "greater": Reading it: term 1 = MSB of wins outright. Term 2 = MSBs tied (), bit 1 breaks it. Term 3 = top two bits tied (), the LSB breaks it. Each lower term is guarded by the equality of all bits above it. Equality is .
L4.2
Two 4-bit 7485 comparators are cascaded to compare 8-bit numbers. The high nibble chip uses The high chip finds its 4 bits all equal (, ), and the low nibble reports so . What is ? Interpret it.
Recall Solution
Interpretation: the high nibble didn't decide (its bits all matched, ), so it passes through the low chip's verdict. The low chip says , so the whole 8-bit result is . This is the human "first differing digit" rule lifted from single bits to whole 4-bit chips.
L4.3
For the cascade, the low nibble's own cascade inputs are tied to (and the greater/less inputs to ). Explain why this exact wiring is required for total equality to work.
Recall Solution
If every bit of both 8-bit numbers is equal, each chip has and . The low chip then computes — but only because we forced at the bottom of the chain. That tie value ripples up: the high chip sees from below and, with , outputs . Tie the bottom greater/less inputs to so they never falsely trigger. Rule of thumb: the very bottom of any cascade must default to "equal" so that "all bits match" correctly bubbles to the top.
Level 5 — Mastery
L5.1 (degenerate case)
What does a comparator output when ? Trace it through and confirm .
Recall Solution
Every bit matches (), so each . Then In , every term contains a factor , so . Likewise has factors , so . Result — zero equals zero, and holds even in this degenerate all-zero case.
L5.2 (extreme values)
Compare the two 4-bit extremes () and (). Show which output fires using only the top term of .
Recall Solution
The very first term is . Since is a sum (OR) of terms, one true term makes ; the guard chain below is irrelevant. Decimal: . ✔ Equality dies immediately because zeroes the product. So .
L5.3 (signed-vs-unsigned pitfall)
An unsigned comparator compares the bit patterns and and outputs . But if these were two's-complement signed numbers, = and = , so truly . What is the fix, and why does the plain comparator "fail"?
Recall Solution
The plain magnitude comparator is correct for unsigned numbers — it never claimed to handle signs. As unsigned, , so is right. The "failure" is only if you mis-interpret the MSB.
Fix for signed: the MSB is a sign bit, not a magnitude bit. Swap its meaning — a in the MSB means smaller (negative), not larger. Concretely, invert both MSBs before feeding them in, or XOR the MSB comparison. After inverting the sign bits, -flavoured, -flavoured, and the same comparator now reports correctly. This is exactly the sign-bit trick used in Binary Subtraction.
Numeric check: unsigned (comparator output), signed (after sign fix).
Recall summary
Recall One-line answers to lock in
Which bit decides magnitude first? ::: The MSB — the first differing bit from the top. Why guard lower-bit terms with ? ::: So they only fire when all higher bits tied; prevents contradictory and . Cascade default at the bottom of a 7485 chain? ::: , others , so a full tie propagates up. All-zero input ? ::: — equality holds, sum still . Fix for signed comparison? ::: Invert the MSBs (sign bits) before comparing.
Connections
- Comparators — the parent note these exercises drill
- XOR and XNOR Gates — the equality primitive
- Truth Tables and Minterms — L1/L3 read outputs directly from these
- Binary Subtraction — the sign-bit method behind L5.3
- 7485 IC — the cascade in L4
- Ripple Carry Adder — the LSB-first contrast in the L3 trap
- Multiplexers — another decision-making combinational block