The magnitude comparator
Not every circuit computes a number. This one returns a verdict: is A bigger than, equal to, or smaller than B?
Built from first principles.
Before you start
What you need first
- The design method — spec → truth table → expression.
- XOR / XNOR — the "are these two bits equal?" gate.
What you'll be able to do
- Derive the three outputs of a 1-bit comparator.
- Compare multi-bit numbers MSB-first.
- Read the comparator block and name a real comparator IC.
Comparing one bit: three outputs
A comparator answers three questions at once, so it has three outputs:
A>B, A=B, A<B (exactly one is 1 at a time). For a
single bit each pair:
| A | B | A>B | A=B | A<B |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
Reading each column off the table:
"Greater" means A is 1 while B is 0; "less" is the mirror; "equal" is just XNOR — the bits match. Wrap those three outputs in a block and you have a comparator:
A = 1, B = 0 the "greater-than" output
A·B′ = 1·1 = 1 — the other two are 0. The block always lights exactly one
verdict.Comparing wider numbers: most-significant bit first
To compare two multi-bit numbers, scan from the most-significant bit downward. The first position where the bits differ decides the whole result — higher bits always outweigh lower ones. Only if a position is equal do you look at the next bit down.
Compare A = 1010 and B = 1100 (4-bit unsigned)
| Bit (MSB→) | A | B | verdict |
|---|---|---|---|
| bit 3 | 1 | 1 | equal → look lower |
| bit 2 | 0 | 1 | differ → B wins |
| bit 1 | (not needed — already decided) | ||
| bit 0 | (not needed) | ||
In the real world
Comparators are sold as ready-made chips — the 74HC85 is a classic 4-bit magnitude comparator, with cascade inputs so you can chain several to compare wider numbers.
✏️ Try it yourself
(a) Write the three 1-bit comparator outputs. (b) Which output is active for A=1, B=0? (c) In what bit order do you compare multi-bit numbers, and why? (d) Compare A=0111 and B=1000 — which is larger?
Recap — the whole topic on one screen
| Idea | What you own now |
|---|---|
| Three outputs | A>B, A=B, A<B — exactly one active |
| 1-bit logic | A·B′, (A⊕B)′, A′·B |
| Multi-bit rule | scan MSB → LSB; first differing bit decides |
| Real chip | 74HC85 (4-bit, cascadable) |