4-Bit Equal Comparator
Build a 4-bit equality comparator that checks if two 4-bit binary numbers are identical—scaling up from 1-bit to real multi-bit comparison!
Overview
Scaling from 1-bit to 4-bit equality comparison reveals a powerful pattern: compare each bit position independently, then combine the results. Each bit pair is checked with an XNOR gate (XOR + NOT), producing 1 if equal. If ALL four bit pairs are equal, the numbers are equal. The four XNOR outputs are combined—if any bit differs, the result is "not equal." This is how real comparator ICs like the 74LS85 check multi-bit equality.
Components Needed
- 1x SN74HC04 IC (Hex Inverter)
- 1x SN74HC86 IC (Quad XOR)
- 1x SN74LS32 IC (Quad OR)
- 1x LED
- severalx Wires
Instructions
Gather Your Materials and Tools
Collect the SN74HC04, SN74HC86, and SN74LS32 ICs, one LED, wires, breadboard, and 5V power supply. You'll also need two 4-bit switch tools to input two 4-bit numbers for comparison.
Reference: 4-Bit Switch Tool
The 4-bit switch tool provides clean binary inputs for testing. Two switch tools give you two 4-bit numbers (A and B) to compare. If you haven't built the switch tool yet, see the 4-bit switch tool project.
Identify the SN74HC04 Inverter IC
The 74HC04 provides the NOT gates to convert XOR outputs to XNOR outputs. We'll use up to four of its six inverters.
Identify the SN74HC86 XOR IC
The 74HC86 provides four XOR gates—one per bit position. Each XOR checks if the corresponding bits of A and B differ.
Identify the SN74LS32 OR IC
The 74LS32 provides OR gates to combine the difference signals. If any XOR output is HIGH (bits differ), the OR chain passes this through.
Wire the 4-Bit Comparator
Place all three ICs on the breadboard and connect power. Wire each bit of A and B to a XOR gate (4 XOR gates total for bits 0-3). Route the XOR outputs through OR gates to detect any difference. Invert the final OR output with a NOT gate to produce the equality signal. Connect to the LED.
Test: 0000 = 0000 → LED ON
Set both switch tools to 0000. All bits match, so all XOR outputs are 0, the OR chain output is 0, and the inverter produces 1. LED turns ON—the numbers are equal!
Test: 0001 ≠ 0000 → LED OFF
Top row: 0001, bottom row: 0000. Bit 0 differs, so the XOR for that bit outputs 1, the OR chain passes it through, and the inverter outputs 0. LED is OFF—numbers are not equal.
Test: 0001 ≠ 0100 → LED OFF
Top row: 0001, bottom row: 0100. Multiple bits differ. The LED stays OFF.
Test: 0001 ≠ 0110 → LED OFF
Top row: 0001, bottom row: 0110. Again, numbers differ and LED is OFF.
Test: 0110 = 0110 → LED ON
Set both rows to 0110 (decimal 6). All four bits match, so the LED turns ON! The comparator correctly detects equality regardless of the specific value.
Test: 0110 ≠ 1110 → LED OFF
Top row: 0110, bottom row: 1110. Only the MSB differs, but that's enough—the LED is OFF. Even a single bit difference means inequality.
Test: 1111 = 1111 → LED ON
Set both rows to 1111 (decimal 15). All bits match and the LED turns ON. You've verified the comparator works across multiple test cases!
Challenges
- Extend to 8 bits by adding another XOR IC and expanding the OR chain
- Add a "not equal" output alongside the equal output
- Combine with magnitude comparators for a full 4-bit comparison circuit
- Calculate the gate delay through your comparator—how many gate levels deep is it?