What a comparator outputs
A comparator takes two binary numbers, A and B, and produces three mutually-exclusive outputs: A>B, A=B, and A<B — exactly one of which is active for any given pair of inputs.
A 1-bit comparator from gates
For single bits A and B, all three outputs reduce to simple Boolean expressions:
- A=B → ¬(A ⊕ B) (XNOR — equal when both bits match)
- A>B → A · ¬B (only 1 when A is 1 and B is 0)
- A<B → ¬A · B (only 1 when A is 0 and B is 1)
Cascading bits into a 4-bit comparator
Comparing multi-bit numbers works from the most significant bit down: if the top bits already differ, that alone decides the result, regardless of every lower bit. Only when the top bits are equal does the comparison need to look at the next bit down. A 4-bit comparator chains four 1-bit comparator stages together with this priority logic, the same cascading principle used by priority encoders.
Comparator vs subtractor
A subtractor (built from full adders, as in the half adder / full adder article) can also tell you which number is larger — if A−B underflows (borrows), A was smaller — but a dedicated comparator is simpler and faster when you only need the relational result and don't need the numeric difference itself.
Where they're used
Comparators drive conditional branches in a CPU (comparing a register against zero or against another register), bound-checking logic in memory controllers, and threshold detection in control systems. Boolflow's built-in Comparator (1-bit) and CMP4 (4-bit) blocks implement exactly this — load a comparator example and toggle the inputs to see GT/EQ/LT switch live, then confirm the behaviour against a truth table.