Comparison Logic · Three outputs, three different stories

2-Bit Magnitude Comparator

Compare two 2-bit numbers, A (bits A1 A0) and B (bits B1 B0), and produce three outputs: A>B, A<B, and A=B. All three are functions of the same four inputs — and minimizing all three side by side shows how differently otherwise-related outputs can behave.

The setup

With A1, A0, B1, B0 as the four inputs (mapped to A, B, C, D in the tool below), each output is 1 for exactly the input combinations where that comparison holds. There are 16 total combinations, split three ways: 6 where A>B, 6 where A<B, and 4 where A=B.

A > B: groups cleanly

A>B = A1B1′ + A0B1′B0′ + A1A0B0′

Three terms — an asymmetric, clean result. This is the case pre-loaded in the tool below.

A < B: groups just as cleanly, mirrored

A<B = A1′A0′B0 + A1′B1 + A0′B1B0

Structurally the mirror image of A>B, as you'd expect — swap the roles of A and B and you get the same shape of result.

A = B: the checkerboard case again

A=B = A1′A0′B1′B0′ + A1′A0B1′B0 + A1A0′B1B0′ + A1A0B1B0

Four full 4-literal terms, none combinable — the same structural pattern as the parity checker and the full adder's Sum output. Equality comparison is fundamentally an XNOR relationship between corresponding bits, and XNOR (like XOR) produces a checkerboard truth table that K-map grouping can't do anything with. Three outputs from the same four inputs, and the "equals" case is the one that resists simplification every time — worth remembering before assuming a comparator will always minimize nicely.

Try A>B live

Input
Karnaugh Map
Minimal Result
Output format
F = 0
Prime Implicant Analysis
Auto-generated Circuit
Universal Gate Conversion

Frequently asked questions

Do the three outputs need three separate circuits?

As minimized here, yes — each is its own independent SOP expression built from its own grouping. In practice, some gate-sharing is often possible between them since they're derived from the same inputs, though that's a separate optimization from single-output K-map minimization.

Could you derive A=B from A>B and A<B instead of minimizing it directly?

Yes — A=B is logically NOT(A>B) NOR (A<B), i.e. neither greater nor less. Whether that's cheaper than the direct 4-term result depends on whether you're already building the other two outputs anyway.

Does this scale sensibly to 3-bit or 4-bit comparators?

The same approach works, but the variable count doubles (6 inputs for 3-bit, 8 for 4-bit), which is beyond a single K-map's practical range — larger comparators are typically built by chaining smaller comparator stages rather than minimizing one giant map.