2-Bit Comparator
A magnitude comparator compares two binary numbers and says which is bigger. This one takes AB and CD — two 2-bit numbers — and lights exactly one of three outputs: AB > CD, AB = CD or AB < CD.
Try it live
This is the Circuit Simulator itself, running in the page — it is LogicsBench's own example design, read-only. Open it full size, and sign in to make your own copy to change.
- Set AB to 10 (two) and CD to 01 (one): only AB>CD lights.
- Open the Truth table tab and check that exactly one output is 1 on every row.
2-bit comparator truth table
| A | B | C | D | AB>CD | AB=CD | AB<CD |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 1 | 0 |
How it works
AB>CD = AC′ + BC′D′ + ABD′AB=CD = (A ⊙ C)(B ⊙ D)AB<CD = A′C + A′B′D + B′CD
The most significant bits decide first: if A and C differ, the number with the 1 is bigger, whatever B and D are.
Only when A equals C do B and D get a say.
Equal needs every bit to match — an XNOR per bit, ANDed. The 74LS85 does the same for four bits, and chains for more.