CE2704 · Digital Logic Design
Theme 4 · Combinational building blocks

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:

ABA>BA=BA<B
00010
01001
10100
11010

Reading each column off the table:

$$ (A>B) = A\cdot B' \qquad (A=B) = (A\oplus B)' \qquad (A

"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 B > = < COMP
Comparator block: A, B in; A>B, A=B, A<B out.
For 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.

📐 Worked example

Compare A = 1010 and B = 1100 (4-bit unsigned)

Bit (MSB→)ABverdict
bit 311equal → look lower
bit 201differ → B wins
bit 1(not needed — already decided)
bit 0(not needed)
$$ A < B \quad (10 < 12) $$
The MSBs tied, but at bit 2 we found A = 0 and B = 1 — so B is larger, and the lower bits can't change that.

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.

Where you'd use one: a digital tachometer comparing the measured RPM of a spindle against a setpoint — output "too slow / on target / too fast" drives the controller. Any "is the reading above/below a threshold?" decision is a comparator.

✏️ 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?

(a) (A>B)=A·B′, (A=B)=(A⊕B)′, (A<B)=A′·B. (b) the greater-than output, A>B. (c) MSB first — the first differing higher-order bit dominates. (d) bit 3: A=0, B=1 → B is larger (7 < 8), decided at the MSB.

Recap — the whole topic on one screen

IdeaWhat you own now
Three outputsA>B, A=B, A<B — exactly one active
1-bit logicA·B′, (A⊕B)′, A′·B
Multi-bit rulescan MSB → LSB; first differing bit decides
Real chip74HC85 (4-bit, cascadable)

Next topic

Multiplexer & demultiplexer

So far blocks have computed answers. Next come blocks that route data: pick one of many signals onto a wire, or send one signal to a chosen destination.

→ Multiplexer & demultiplexer