Number comparator with gates
Build it step by step
0 of 7 doneDraw the truth table
List all 16 combinations of A and B.
Make equality
XOR each bit pair and invert the result.
Combine equality
AND the two equality bits for A = B.
Make greater-than
Build A1·¬B1 + E1·A0·¬B0.
Make less-than
NOR of greater and equal.
Wire the LEDs
Resistors and LEDs on the three outputs.
Test all 16 cases
Tick each against the table.
How do you build a number comparator with gates?
Gates compare two 2-bit numbers and light A > B, A = B or A < B. You need 74HC86 quad XOR gate, 74HC08 quad AND gate × 2, 74HC32 quad OR gate, 74HC04 hex inverter, DIP switch 8-position, Resistor 10 kΩ × 4, LED 5 mm red, LED 5 mm green, LED 5 mm yellow, Resistor 330 Ω × 3, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and 9 V battery snap with DC jack. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 13
Parts list
- Integrated CircuitsBuy
- Integrated CircuitsBuy
- Integrated CircuitsBuy
- Integrated CircuitsBuy
- SwitchesBuy
- PassivesBuyResistor 10 kΩ × 4
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- SemiconductorsBuyLED 5 mm yellow × 1
- PassivesBuyResistor 330 Ω × 3
- PrototypingBuy
- PrototypingBuy
- PowerBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Switches A1, A0 (number A) | Each between 5 V and the gate input, 10 kΩ pull-down to GND | Inputs A |
| Switches B1, B0 (number B) | Same, with 10 kΩ pull-downs | Inputs B |
| XOR gate (74HC86) | A1 with B1, and A0 with B0, then each XOR output through an inverter (74HC04) | Equality bits E1 and E0 |
| First AND gate (74HC08) | E1 and E0 | A = B |
| Inverter on B1 | AND with A1 | A1 greater than B1 (G1) |
| Inverter on B0 | AND with A0, then AND with E1 | A0 greater at equal top bit (G0) |
| OR gate (74HC32) | G1 and G0 | A > B |
| NOR of A > B and A = B (OR then inverter) | Third LED | A < B |
| Each output | 330 Ω resistor and an LED to GND | Green for A > B, yellow for A = B, red for A < B |
| Supply | 5 V to pin 14 and GND to pin 7 of every chip | Power (use 5 V from a regulated supply; 74HC also runs at 3 V) |
No code needed
With A = A1A0 and B = B1B0: A equals B when both bits match, so E1 = XNOR(A1, B1) and E0 = XNOR(A0, B0), and A = B is E1 AND E0. A is greater than B if A1 beats B1 (A1 AND NOT B1), or if the top bits are equal and A0 beats B0 (E1 AND A0 AND NOT B0). A is less than B when neither of those holds, so it is NOT (A > B OR A = B). Draw the truth table with all 16 cases first and check each output against it. Tie every unused input of every chip to ground or 5 V, never leave a CMOS input floating. Add a 100 nF capacitor across the supply near the chips. On the 74HC chips the four gates in a package use pins 1 to 3, 4 to 6, 8 to 10 and 11 to 13, with pin 14 for supply and pin 7 for ground; the 74HC04 inverters use input then output pins (1 to 2, 3 to 4, 5 to 6, 9 to 8, 11 to 10, 13 to 12).
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| A = B = 00 | Only the yellow LED lights |
| A = 10, B = 01 | Green lights |
| A = 01, B = 11 | Red lights |
| All 16 cases | Exactly one LED lit each time |
If it does not work
No LED lights
Check the 5 V and ground on pins 14 and 7.
Two LEDs lit
Check the NOR for A < B and the equality chain.
Odd results
Check every unused input is tied low or high.
LED dim
Use the right resistor values and check the chips are 74HC.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the number comparator with gates?
74HC86 quad XOR gate, 74HC08 quad AND gate × 2, 74HC32 quad OR gate, 74HC04 hex inverter, DIP switch 8-position, Resistor 10 kΩ × 4, LED 5 mm red, LED 5 mm green, LED 5 mm yellow, Resistor 330 Ω × 3, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and 9 V battery snap with DC jack.
How long does the number comparator with gates take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the number comparator with gates works?
A = B = 00: Only the yellow LED lights. A = 10, B = 01: Green lights. A = 01, B = 11: Red lights.
No LED lights: what should I check?
Check the 5 V and ground on pins 14 and 7.
Two LEDs lit: what should I check?
Check the NOR for A < B and the equality chain.
Odd results: what should I check?
Check every unused input is tied low or high.
LED dim: what should I check?
Use the right resistor values and check the chips are 74HC.
