1-Bit Less Than Comparator
Build a 1-bit "less than" comparator using a NOT gate and an AND gate—detect when input A is less than input B!
Overview
After building an equality comparator, the next step is detecting magnitude—is one value less than another? For single bits, A < B is true only when A=0 and B=1. This can be expressed as NOT(A) AND B. This simple two-gate circuit is a fundamental building block for magnitude comparators used in sorting algorithms, priority encoders, and CPU arithmetic.
Components Needed
- 1x SN74HC04 IC (Hex Inverter)
- 1x CD4081 IC (Quad AND)
- 2x Switch
- 1x LED
- severalx Wires
Instructions
Gather Your Components
Collect the SN74HC04 hex inverter IC, the CD4081 quad AND gate IC, two switches (left for A, right for B), one LED, wires, breadboard, and 5V power supply.
Identify the SN74HC04 Inverter IC
The SN74HC04 contains six independent NOT gates. We'll use one inverter to create NOT(A). Pin 1 is input, Pin 2 is output for the first inverter. Pin 7 is ground, Pin 14 is VCC.
Identify the CD4081 AND Gate IC
The CD4081 contains four 2-input AND gates. Pins 1 and 2 are inputs to the first gate, Pin 3 is its output. Pin 7 is VSS (ground), Pin 14 is VDD (power). We'll feed NOT(A) and B into one AND gate.
Wire the Less Than Comparator
Place both ICs on the breadboard and connect power. Wire the left switch (A) to an inverter input on the 74HC04. Connect the inverter output (NOT A) and the right switch (B) to an AND gate on the CD4081. Connect the AND gate output to the LED. The LED lights when A < B.
Test: A=0, B=0 → LED OFF (0 is not < 0)
Both switches OFF. A=0 and B=0, so A is not less than B. NOT(0)=1, but B=0, so AND(1,0)=0. LED is OFF.
Test: A=0, B=1 → LED ON (0 < 1)
Left switch (A) OFF, right switch (B) ON. A=0 and B=1, so A IS less than B! NOT(0)=1, B=1, so AND(1,1)=1. The LED turns ON—this is the only case where A < B is true for single bits.
Test: A=1, B=0 → LED OFF (1 is not < 0)
Left switch (A) ON, right switch (B) OFF. A=1 and B=0. NOT(1)=0, so AND(0,0)=0 regardless of B. LED is OFF—1 is not less than 0.
Test: A=1, B=1 → LED OFF (1 is not < 1)
Both switches ON. A=1 and B=1. NOT(1)=0, so AND(0,1)=0. LED is OFF—equal values are not less than each other. You've verified all four combinations!
Challenges
- Swap the inverter to B instead of A—now you have a "greater than" comparator!
- Combine less-than, equal, and greater-than into a full 1-bit comparator
- Extend to 2 bits by adding logic for the higher-order bit
- Think about how you'd cascade this for 4-bit or 8-bit comparison