1-Bit Equal Comparator

Build a 1-bit equality comparator using an XOR gate and an inverter—detect when two single-bit inputs are the same!

Overview

Comparing two values is one of the most fundamental operations in digital systems—CPUs do it constantly for branching, sorting, and decision-making. This project builds the simplest comparator: a 1-bit equality checker. An XOR gate outputs HIGH when inputs differ, so by inverting that output, you get HIGH when inputs are EQUAL. This elegant use of just two gates forms the core building block for larger multi-bit comparators.

Components Needed

  • 1x SN74HC04 IC (Hex Inverter)
  • 1x SN74HC86 IC (Quad XOR)
  • 2x Switch
  • 1x LED
  • severalx Wires

Instructions

  1. Gather Your Components

    Collect the SN74HC04 hex inverter IC, the SN74HC86 quad XOR gate IC, two switches (for inputs A and B), one LED (to show equality), wires, breadboard, and 5V power supply.

  2. Identify the SN74HC04 Inverter IC

    The SN74HC04 contains six independent NOT gates. Pin 1 is input to the first inverter, Pin 2 is its output. Pin 7 is ground, Pin 14 is VCC. We'll use one inverter to flip the XOR output into an equality signal.

  3. Identify the SN74HC86 XOR IC

    The SN74HC86 contains four 2-input XOR gates. Pins 1 and 2 are inputs to the first gate, Pin 3 is its output. Pin 7 is ground, Pin 14 is VCC. The XOR gate detects when inputs differ.

  4. Wire the Comparator Circuit

    Place both ICs on the breadboard. Connect power (Pin 14 to 5V, Pin 7 to GND) for both chips. Wire the two switches to the XOR gate inputs (Pins 1 and 2 of the 74HC86). Connect the XOR output (Pin 3) to an inverter input on the 74HC04. Connect the inverter output to the LED. The LED will light when the inputs are equal.

  5. Test: Both Switches OFF (0=0) → LED ON

    With both switches OFF, both inputs are 0. Since 0 equals 0, the comparator outputs HIGH and the LED turns ON. The XOR sees matching inputs (both LOW) and outputs LOW, which the inverter flips to HIGH.

  6. Test: Input 01 (0≠1) → LED OFF

    Set the left switch OFF and right switch ON (inputs 0 and 1). The inputs are different, so the comparator outputs LOW and the LED turns OFF. The XOR detects the difference and outputs HIGH, which the inverter flips to LOW.

  7. Test: Input 10 (1≠0) → LED OFF

    Set the left switch ON and right switch OFF (inputs 1 and 0). Again the inputs differ, so the LED stays OFF. The comparator doesn't care which input is larger—just whether they match.

  8. Test: Both Switches ON (1=1) → LED ON

    Turn both switches ON. Both inputs are 1, and since 1 equals 1, the LED turns ON again. You've verified all four input combinations—the comparator correctly identifies equality in every case!

Challenges

  • Remove the inverter—now you have an inequality detector. When does the LED light?
  • Build a 2-bit equality comparator by adding a second XNOR and an AND gate
  • Chain four XNOR gates with a 4-input AND to compare two 4-bit numbers
  • Compare this XNOR approach to using a subtractor for equality detection