3.3.9 · D5Combinational Circuits

Question bank — Comparators

1,514 words7 min readBack to topic

Notation used below (all built in the parent Comparators):

  • — the two unsigned binary numbers being compared.
  • — the outputs "", "", "".
  • — bit (bit is the least significant, LSB; the top bit is the most significant, MSB).
  • — the per-bit equality flag, high when bit of both numbers matches.
  • — NOT ; — XOR ("differ"); — XNOR ("same").

True or false — justify

A raw XOR gate on two bits gives you an equality signal.
False. XOR outputs when the bits differ, so it is an inequality detector; equality is its negation, (XNOR).
For unsigned numbers, even though has more s in it.
True. Magnitude is set by the MSB, not by counting ones: and . The single high MSB of outweighs all three low bits of .
In an -bit comparator, the outputs always satisfy .
True. For any two numbers exactly one of "greater", "equal", "less" holds, so precisely one output is high — the three are mutually exclusive and exhaustive.
You could build a 4-bit comparator by writing a single truth table and reading off minterms.
True in principle, terrible in practice. It needs rows; the MSB-first structured method with guards is the only human-scalable design (see Truth Tables and Minterms).
If the MSBs of and differ, the lower bits have no effect on the result.
True. The highest differing bit decides everything, exactly like the first differing digit when you compare vs . Lower bits are irrelevant once a higher bit breaks the tie.
The expression correctly computes greater-than for a 2-bit comparator.
False. The LSB term is missing its guard: it must be , otherwise the LSB "votes greater" even when the MSB already decided .
XNOR and "equal" mean the same thing at the single-bit level.
True. For one bit, is exactly ; that is why the whole equality output is a product of XNOR terms (see XOR and XNOR Gates).
A comparator needs a clock to work.
False. It is a combinational circuit: outputs depend only on the current inputs, no memory or clock — that is the whole point of doing it with pure gates.

Spot the error

" — equality means at least one bit matches."
Error: wrong operator. Equality needs every bit to match, so it is an AND (product): . Using OR would report "equal" whenever a single bit happened to agree.
" for a 2-bit comparator."
Error: unguarded LSB term. The correct form is . Without the guard the LSB term can fire even when the MSB already made , giving two contradictory outputs high at once.
"Comparators work LSB-first, just like a Ripple Carry Adder."
Error: wrong scan direction. Adders propagate a carry LSB→MSB, but magnitude is dominated by the MSB, so comparators must decide MSB-first. Copying the adder's direction breaks the logic.
"For a 1-bit comparator, and by symmetry."
Error: is the mirror, not the copy. (only ), and (only ). Swapping which variable is inverted is the whole difference between greater and less.
"In a cascaded 7485, feed the local decision through as ."
Error: should be OR, not AND. The correct rule is : either the local bits already decided (), or they tied () and we trust the cascade input.
"To chain two 7485 IC chips for 8 bits, wire the high nibble's outputs into the low nibble's cascade inputs."
Error: direction reversed. The less-significant chip's outputs feed the more-significant chip's cascade inputs, because the high chip decides first and only defers downward when its own bits tie.
" can equal if the two numbers are unrelated."
Error: never zero. Any two unsigned numbers are always one of , , — there is no "unrelated" case, so the sum is always exactly .

Why questions

Why is equality built from XNOR rather than XOR?
Because XOR marks where bits differ; equality is the absence of any difference, which is the negation of XOR, i.e. XNOR — "eXactly No difference".
Why must every lower-bit decision term carry an prefix?
The prefix says "all higher bits were equal, so this is the first differing bit". Without it, a lower bit could override a higher bit that already decided the comparison, violating the MSB-first rule.
Why do we compare from the MSB downward instead of the LSB upward?
Because a single higher-order bit outweighs all lower bits combined (), so the first place the numbers differ, reading from the top, settles the magnitude.
Why does the 7485 provide cascade inputs at all?
So several 4-bit chips can be chained into wider comparators: when a chip's own four bits all tie (), it passes the decision made by a less-significant chip through, extending the first-differing-bit rule across chip boundaries.
Why tie the least-significant chip's to in a cascade?
So that if every bit across all chips matches, the equality signal propagates cleanly to the top output and reports "equal" — the base case of the chain has nothing below it to defer to.
Why can subtraction be used as an alternative comparator?
Computing and inspecting the sign/borrow tells you which is larger (see Binary Subtraction); a negative result means , zero means equal. It answers the same question by a different route.
Why is a comparator grouped with blocks like Multiplexers?
Both are combinational decision-makers: outputs are a pure function of current inputs with no stored state, computing a choice instantly from logic gates alone.

Edge cases

What do the outputs read when ?
All four , so while . Zero equals zero — the equality path fires exactly as for any other tie.
What happens if only the LSB differs, e.g. , ?
The three higher bits tie () and the LSB decides: gives . The guarded LSB term is the one and only active term.
What happens if only the MSB differs, e.g. , ?
The MSB decides immediately: gives , and every lower term is killed because it requires (but the MSBs differ, so ). Lower bits are silenced.
In the 2-bit case, can both and happen together?
No. means the MSBs match, while requires (they differ). They are mutually exclusive, which is why no two of ever fire at once.
For a single 4-bit 7485 used alone (not cascaded), how should the cascade inputs be set?
Set and , so that when all four bits tie the chip reports "equal" rather than an undefined pass-through.
What if two numbers have different bit-widths, say compare -bit with -bit ?
Zero-extend the shorter number to the same width first (). Comparing mismatched widths directly is meaningless; the MSB positions must line up by place value.
Recall One-line self-test
  • XOR vs equality? → XOR = differ, so equality is XNOR.
  • Missing guard causes? → contradictory outputs, lower bit overrides higher.
  • Scan direction? → MSB-first, first differing bit wins.
  • in a 7485 means? → local bits tied, defer to cascade input.
  • ? → always exactly .

Connections

  • Comparators — parent topic this bank drills.
  • XOR and XNOR Gates — the equality primitive the traps revolve around.
  • Truth Tables and Minterms — why the giant-table approach fails at scale.
  • Binary Subtraction — the sign-of-difference alternative.
  • Ripple Carry Adder — contrast: LSB-first vs comparator's MSB-first.
  • 7485 IC — the cascade rules probed in the edge cases.