Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

3-bit magnitude comparator: circuit and equations, live

A 3-bit magnitude comparator compares two 3-bit numbers A2 A1 A0 and B2 B1 B0 and lights exactly one of three outputs: GT for A > B, EQ for A = B and LT for A < B. It decides from the top bit down: the first bit position where A and B differ settles the answer.

Each bit pair is first tested for equality with an XNOR gate, x_i = A_i XNOR B_i, so EQ = x2 x1 x0. A is greater when it has a 1 where B has a 0 at the highest position where they differ: GT = A2 B2' + x2 A1 B1' + x2 x1 A0 B0'. LT is the mirror image with A and B swapped: LT = A2' B2 + x2 A1' B1 + x2 x1 A0' B0. The equality terms x2 and x2 x1 are shared by all three outputs, so the circuit is three XNOR gates, six inverters, a handful of AND gates and two OR chains. All 64 input pairs are checked before the page is built; the live circuit starts at 000 versus 000, so EQ is lit. The same pattern one bit smaller is the 2-bit comparator, one bit larger the 4-bit magnitude comparator, and the 74LS85 chip does 4 bits with cascade inputs, as in the 7485 comparator.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “3-bit magnitude comparator”, https://digiwleea.wleeaf.dev/tools/build/comparator-3bit/

What you need

Step by step

  1. Place inputs A2 to A0 and B2 to B0 and probes GT, EQ and LT.
  2. XNOR each bit pair: x2, x1, x0. EQ is their AND.
  3. For each bit make A_i AND NOT B_i (A bigger here) and NOT A_i AND B_i (B bigger here).
  4. GT: OR together A2 B2', x2 A1 B1' and x2 x1 A0 B0'. LT: the same with A and B swapped.
  5. Try A = 101 and B = 011: the top bits differ (1 and 0), so GT = 1 whatever the lower bits are.

3-bit comparator: sample rows

ABDecided atGTEQLT
000000all bits equal010
101011bit 2100
010011bit 0001
110101bit 1100
011100bit 2001
111111all bits equal010

The full truth table has 64 rows; all of them are checked on the live circuit against a numeric comparison before the page is built.

You can also read the full theory in the lesson on the comparator. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

More builds: Comparing numbers

All 246 build guides, by topic

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the 3-bit magnitude comparator in the lab →

Frequently asked

How do you design a 3-bit magnitude comparator?

XNOR each pair of bits to test equality, x_i = A_i XNOR B_i. Then EQ = x2 x1 x0, GT = A2 B2' + x2 A1 B1' + x2 x1 A0 B0' and LT = A2' B2 + x2 A1' B1 + x2 x1 A0' B0.

How many rows does the truth table of a 3-bit comparator have?

64, one for every combination of the six inputs (2^6). In 8 of them A = B, and the other 56 split evenly: 28 with A > B and 28 with A < B.

Why does a comparator start from the most significant bit?

Because the highest bit position where the numbers differ decides which is larger, whatever the lower bits are, so each lower bit only matters when every bit above it is equal.

Can I build a 3-bit comparator from a 4-bit comparator chip?

Yes: tie the unused top bits A3 and B3 to the same value (both 0) and use the other three bits as normal; with the top bits equal, the result depends only on the lower three.