Home / Learn Verilog / Logic Gates: AND, OR, NOT, NAND, NOR, XOR, XNOR

Logic Gates: AND, OR, NOT, NAND, NOR, XOR, XNOR

The seven basic gates, their symbols, truth and Verilog operators.

The short versionThe seven basic gates, their symbols, truth and Verilog operators.

Theory in plain words

Gate symbolsABYANDa&bABYORa|bAYNOT~aABYNAND~(a&b)ABYNOR~(a|b)ABYXORa^bABYXNOR~(a^b)AYBUFa
Gate symbols

In plain terms

A logic gate is a circuit that computes a Boolean function of its inputs. All digital hardware is built from these gates.

Why we use it

Every Verilog expression eventually becomes gates. Knowing them lets you predict the hardware.

Under the hood

Each gate has a symbol, a truth table and a Verilog operator: & | ~ ^ and combinations. NAND and NOR are universal: any logic can be built from only NAND gates.

Real-world use

  • Every digital circuit
  • FPGA lookup tables
  • Standard cell libraries

All gates at once

Gate truth tableVerilog: edit and run

The loop sets {a,b} to 00, 01, 10, 11 and prints the complete truth table of all gates.

GateVerilogOutput is 1 when...
ANDa & bboth inputs are 1
ORa | bat least one input is 1
NOT~ainput is 0
NAND~(a & b)not both inputs are 1
NOR~(a | b)both inputs are 0
XORa ^ binputs are different
XNOR~(a ^ b)inputs are equal

Quick quiz

1. XOR output is 1 when...

2. Which gate is universal?