The equality comparator: are two numbers equal?
A comparator tells whether two numbers are equal. Here both numbers have 2 bits: A1 A0 and B1 B0. The output EQ must be 1 when they are the same number and 0 otherwise.
Truth table
| A1 | A0 | B1 | B0 | EQ |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Try it Click the inputs to change them.
EQ1
How it works
Two numbers are equal when every pair of matching bits is equal. The XNOR gate is 1 exactly when its two inputs are equal, so one XNOR compares A1 with B1 and another compares A0 with B0. The numbers are equal only if both comparisons say yes: join them with an AND gate.
For 8-bit numbers you would use eight XNORs and one AND with eight inputs. Processors do this every time a program checks whether two values are equal.
Hints and solution
Try on your own first. Each hint gives away a little more.
- Compare bit by bit: XNOR is 1 when its inputs are equal.
- Both bit pairs must be equal.