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
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.
| Gate | Verilog | Output is 1 when... |
|---|---|---|
| AND | a & b | both inputs are 1 |
| OR | a | b | at least one input is 1 |
| NOT | ~a | input is 0 |
| NAND | ~(a & b) | not both inputs are 1 |
| NOR | ~(a | b) | both inputs are 0 |
| XOR | a ^ b | inputs are different |
| XNOR | ~(a ^ b) | inputs are equal |
Quick quiz
1. XOR output is 1 when...
Exclusive OR.
2. Which gate is universal?
NAND (and NOR) can build everything.