Build note

Seven logic gates on a breadboard, and the one wired differently

After working through bitwise operations in C, I wanted to see the same logic on a breadboard instead of on a screen. Not a simulator, not a diagram in a book: real chips, a 5 V rail and an LED that turns on or off. So I worked through the 74HC parts one at a time, writing down what each chip does and how it maps to a line of C.

The notes and the demo code live in c-26-gates in my C playground. This is what the notes cover, including the chip that does not follow the family pinout.

The chips

All six are DIP-14, all run from 2 V to 6 V, and the 74HC04 datasheet gives about a 10 ns propagation delay. That means the output settles long before a human can see anything, which is what makes them useful.

Part Gates What it does
SN74HC04 6 inverters Flips the input
SN74HC08 4 AND Output high only if both inputs are high
SN74HC32 4 OR Output high if either input is high
SN74HC00 4 NAND AND, then inverted
SN74HC02 4 NOR OR, then inverted
SN74HC86 4 XOR Output high when the inputs differ

Every one of them uses pin 14 for VCC and pin 7 for ground. A 0.1 µF capacitor between those two pins, right next to the chip, is not optional in my notes any more. Without it the circuit works until it suddenly does not.

Reading the symbol tells you the gate

The drawings look similar until you know the three features to check, left to right:

  • Shape. A flat back with a rounded front is the AND family. A curved back with a pointed front is the OR and XOR family.
  • An extra arc on the input side means XOR, not OR.
  • A bubble on the output inverts the result: AND becomes NAND, OR becomes NOR, XOR becomes XNOR.

That single rule covers most of the confusion at the start.

The same gates in C

The mapping is direct, which is why the chips make the operators click:

Gate C
NOT !a
AND a && b
OR a || b
NAND !(a && b)
NOR !(a || b)
XOR (a != b) or (a ^ b) & 1

The one that trips people up is ! versus ~. On a single bit they look the same, but ~ flips every bit in the variable. If you are modelling six inverter gates in one byte, you have to mask the result back down or the upper bits come along for the ride:

uint8_t outputs = ~inputs & 0x3F;  // six bits only

That line is the whole difference between “six gates” and “eight gates and some noise”.

The chip that does not share the pinout

Most of the family puts the first gate’s inputs on pins 1 and 2 and its output on pin 3. The 74HC02 does not follow that. Its outputs are on pins 1, 4, 10 and 13, and the inputs move around them. Wire it like the HC00, HC08 or HC32 and you are driving an output with an output while reading an input into an LED: the circuit does nothing useful, and nothing looks obviously wrong.

My own notes disagreed about this for a while. The summary file carried a warning about the 7402 pinout, and the per-chip file claimed it matched the others. The datasheet settled it in about a minute, and the datasheet pinout is the one I keep open while wiring.

Where gates stop being enough

Once the six basics are clear, three more chips make the idea useful:

  • SN74HC14, a Schmitt-trigger inverter. It is still a NOT gate, but it has two switching thresholds instead of one, so a noisy or slow signal gets cleaned up instead of producing a burst of false edges. This is the chip for a button that double-triggers.
  • SN74HC138, a 3-to-8 decoder. Give it three bits and it activates exactly one of eight outputs. The outputs are active-low, so the selected one goes to 0. This is address decoding in its smallest form.
  • SN74HC595, a shift register with a latch. Bits shift in one at a time, then a separate latch clock copies them to the outputs all at once. That second stage is why you do not see flicker while the bits move.

The C side

The 74HC04 folder has a small demo that prints the truth table, inverts a random six-bit pattern and walks through a three-stage ring oscillator. It compiles with make and runs on the desktop; it simulates the logic, it does not read the hardware.

Input pattern:  100111 (Decimal: 39)
Output pattern: 011000 (Decimal: 24)

That is the same inversion as the chip, with the mask doing the work.

Rules I write on the parts box now

  • Look up the pinout for every part, even inside one family. The 7402 is not the exception I expected, and I now assume nothing.
  • Fit the 0.1 µF decoupling capacitor first, before the interesting wiring.
  • Never leave a CMOS input floating. Tie unused inputs to ground or VCC, or the output does whatever it likes.
  • Use an IC socket. Pulling a chip that is wired on all 14 pins is a good way to bend one.

How this was made

  • Written by: Rupesh, from his own repo notes, wiring and demo code, with AI drafting and editing.
  • Numbers and measurements: from the part datasheets and the demo output.
  • AI-assisted sections: structure and copy editing.