4-Bit Full Comparator (Less, Equal, Greater)
Build a complete 4-bit magnitude comparator with three outputs—less than, equal, and greater than—the most complex combinational circuit yet!
Overview
This is the culmination of the comparator series—a full 4-bit magnitude comparator that simultaneously determines if number A is less than, equal to, or greater than number B. With 11 ICs on the breadboard, this is a substantial build that demonstrates how simple gate-level operations scale to real-world functionality. The same logic is integrated into comparator ICs like the 74LS85 and is fundamental to CPU arithmetic logic units.
Components Needed
- 3x SN74LS32 IC (Quad OR)
- 5x CD4081 IC (Quad AND)
- 3x SN74LS04 IC (Hex Inverter)
- 3x LED
- severalx Wires
Instructions
Gather Your Materials
This project requires a significant number of ICs: 3 SN74LS32 (OR), 5 CD4081 (AND), and 3 SN74LS04 (NOT) chips, plus 3 LEDs, lots of wires, and two 4-bit switch tools for input.
Reference: 4-Bit Switch Tool
You'll need two 4-bit switch tools to provide the two 4-bit input numbers. These make testing much easier than individual switches.
Identify the SN74LS04 Inverter IC
The 74LS04 provides NOT gates for inverting bits and creating XNOR (equality) signals. You'll use three of these chips to have enough inverters for all the logic.
Identify the CD4081 AND Gate IC
The CD4081 provides AND gates for the magnitude comparison logic. Five chips give you 20 AND gates for the cascading comparison at each bit level.
Identify the SN74LS32 OR Gate IC
The 74LS32 provides OR gates to combine the comparison results from each bit position into the final less-than, equal, and greater-than outputs.
Wire the Complete Comparator
This is the most complex wiring yet. For each bit position (3 down to 0), create the three comparison signals (>, =, <). Gate each bit's magnitude result with the equality of all higher bits. Finally, OR all the gated greater-than signals together, and OR all the gated less-than signals together. The overall equality is the AND of all four bit equalities.
Connect the 4-Bit Switch Tools
Connect both 4-bit switch tools to provide inputs A (top row) and B (bottom row). The three LEDs show the comparison result: left LED for A>B, middle for A=B, right for A<B.
Test: A=0110, B=0000 → 100 (A > B)
Top switches: 0110 (decimal 6), bottom: 0000 (decimal 0). Since 6 > 0, the left LED (greater than) lights. Output: 100.
Test: A=0000, B=0110 → 001 (A < B)
Swap the values—top: 0000, bottom: 0110. Now 0 < 6, so the right LED lights. Output: 001.
Test: A=0101, B=0101 → 010 (A = B)
Both rows: 0101 (decimal 5). The numbers are equal, so the middle LED lights. Output: 010.
Test: A=1101, B=1101 → 010 (A = B)
Both rows: 1101 (decimal 13). Equal again, middle LED lights. Output: 010.
Test: A=1100, B=1001 → 100 (A > B)
Top: 1100 (decimal 12), bottom: 1001 (decimal 9). The MSBs are equal, so bit 2 decides: A has 1, B has 0. A > B. Output: 100.
Test: A=0000, B=1111 → 001 (A < B)
Top: 0000 (decimal 0), bottom: 1111 (decimal 15). The minimum vs maximum. Output: 001.
Test: A=1111, B=0000 → 100 (A > B)
Reversed—top: 1111, bottom: 0000. Maximum vs minimum. Output: 100.
Test: A=1001, B=1011 → 001 (A < B)
Top: 1001 (decimal 9), bottom: 1011 (decimal 11). MSBs match, second bits match, but bit 1 decides: A has 0, B has 1. A < B. Output: 001.
Challenges
- Replace all 11 ICs with a single 74LS85 4-bit comparator IC and compare the simplicity
- Cascade two of these circuits for 8-bit comparison
- Add a 7-segment display to show the decimal values being compared
- Calculate the worst-case propagation delay through your comparator