Comparators
1. What are we actually building?
WHAT is the simplest one? A 1-bit comparator. Compare a single bit against a single bit .
HOW do we start? Write the truth table — 2 inputs → 4 rows.
| 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
2. Deriving the 1-bit logic from scratch
WHY these equations? Read the truth table column by column and translate each "1" into a product term.
: the only row where this is 1 is . That is the product term .
: the only 1 is at , i.e. .
: 1 when both are 0 or both are 1. That is exactly the XNOR:
3. Building a multi-bit comparator (the real trick)
WHY not just a giant truth table? For -bit numbers you'd need rows — for 4-bit that's 256 rows. Impossible to hand-design. We need a structured, first-principles method: think like a human comparing numbers.
HOW to formalise for bits. Let , .
Define per-bit equality (1 when bit matches).
happens if, scanning from the top, the highest differing bit has , and all higher bits were equal:
WHY the chain? The term means "all bits above position were equal, so this is the first place they differ" — exactly the human rule.
Symmetrically:
And equality is "every bit matches":

4. Worked example — 2-bit comparator from scratch
Compare with .
Step 1 — per-bit equals. , . Why this step? These are the reusable "match" signals the human method needs.
Step 2 — Equal. Both bits match: Why? Numbers are equal only if MSB and LSB agree.
Step 3 — Greater. MSB decides first; if MSBs tie, LSB decides: Why? First term: MSB of wins outright. Second: MSBs equal (), so LSB breaks the tie.
Step 4 — Less. Mirror image:
Check with , : → . ✔ (2 > 1)
Check with , : → . ✔
5. Worked example — the IC 7485 (4-bit) cascade
WHY care? Real chips like the 7485 take cascade inputs so you can chain them for wider numbers.
Rule when tie occurs internally: if the 4 local bits are all equal, the chip passes through the cascade input.
Why this step? means "these 4 bits didn't decide anything, so trust the less-significant chip below" — again the human first-differing-digit rule, now across whole chips.
Cascade wiring for 8-bit: feed the low nibble's outputs into the high nibble's cascade inputs. The low chip's ground-level inputs are tied (so if everything equals, output equals).
6. Common mistakes
7. Active recall
Recall Test yourself (hide answers)
- Which gate implements 1-bit equality? → XNOR
- Which bit decides magnitude first? → the MSB
- Why guard lower-bit terms with ? → so they only act when higher bits tied
- What does do in a cascaded 7485? → passes cascade input through
- Sum identity that must always hold? →
Recall Feynman: explain to a 12-year-old
Imagine two kids showing number cards, biggest first. They flip the front card: if one is bigger, that kid wins the whole game — no need to look further. If the front cards match, they move to the next card, and so on. If every card matches, it's a tie. A comparator is a tiny electric machine that plays this exact card game with 1s and 0s, instantly.
8. Flashcards
What three outputs does a comparator produce?
1-bit equality equation?
1-bit greater-than equation?
1-bit less-than equation?
Why compare MSB first?
Purpose of the signals?
2-bit greater-than expression?
n-bit equality expression?
What identity always holds among comparator outputs?
Role of cascade inputs in the 7485 IC?
7485 cascaded output formula for A>B?
Common XOR-vs-XNOR trap?
9. Connections
- XOR and XNOR Gates — the equality primitive
- Truth Tables and Minterms — how we read out
- Binary Subtraction — subtracting and checking the sign bit is an alternate comparison method
- Multiplexers — another decision-making combinational block
- Ripple Carry Adder — contrast: adders go LSB-first, comparators go MSB-first
- 7485 IC — the standard cascadable comparator chip
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Comparator ka kaam simple hai: do binary numbers aur ko compare karo aur batao kaun bada hai — teen output milte hain: , , aur . Ek time pe sirf ek hi output high hota hai, isliye hamesha true rahta hai. Sabse chhota comparator 1-bit ka hota hai: , , aur equality ke liye XNOR use hota hai kyunki XNOR tabhi 1 deta hai jab dono bits same ho.
Sabse important intuition: hum numbers ko MSB se compare karte hain, LSB se nahi. Jaise aap 3746 aur 3752 compare karte ho — aage se digit dekhte ho, jahan pehli baar difference milta hai wahi decide kar deta hai, baaki digits matter nahi karte. Hardware bhi bilkul yehi karta hai. Isliye har lower-bit term ko (matching flag) se "guard" karte hain — matlab lower bit tabhi bolega jab upar ke saare bits equal ho.
Common galti: log equality ke liye XOR laga dete hain, par XOR to "difference" batata hai, ulta jawab. Equality ke liye hamesha XNOR. Doosri galti: LSB se compare karna — galat, kyunki hota hai even though LSBs mein bade dikhte hain.
Real chips jaise 7485 mein cascade inputs hote hain taaki chhote comparators ko jodkar bade numbers compare kar sako. Rule: agar local 4 bits sab equal ho (), to niche wale (less-significant) chip ka jawab pass kar do — same MSB-first logic, bas ab poore chips ke level pe.