Logic Gates and Truth Tables
Logic gates are the atoms of digital hardware. Every processor, memory and accelerator is, at the bottom, millions of these few primitive gates wired together. This chapter defines each gate by its truth table and shows them running.
The primitive gates
AND outputs 1 only when all inputs are 1. OR outputs 1 when any input is 1. NOT (inverter) flips its input. XOR outputs 1 when the inputs differ — the basis of adders and parity. NAND and NOR are AND/OR followed by inversion and are functionally complete: any logic function can be built from NAND gates alone, which is why silicon libraries lean on them.
The testbench sweeps all four input combinations and prints the truth table for every gate at once:
module tb;
reg a, b;
initial begin
$display(" a b | AND OR XOR NAND NOR");
{a,b}=2'b00; #1 $display(" %b %b | %b %b %b %b %b", a,b, a&b, a|b, a^b, ~(a&b), ~(a|b));
{a,b}=2'b01; #1 $display(" %b %b | %b %b %b %b %b", a,b, a&b, a|b, a^b, ~(a&b), ~(a|b));
{a,b}=2'b10; #1 $display(" %b %b | %b %b %b %b %b", a,b, a&b, a|b, a^b, ~(a&b), ~(a|b));
{a,b}=2'b11; #1 $display(" %b %b | %b %b %b %b %b", a,b, a&b, a|b, a^b, ~(a&b), ~(a|b));
$finish;
end
endmodulea b | AND OR XOR NAND NOR 0 0 | 0 0 0 1 1 0 1 | 0 1 1 1 0 1 0 | 0 1 1 1 0 1 1 | 1 1 0 0 0
Check yourself
What does it mean that NAND is “functionally complete”?
Any Boolean function — AND, OR, NOT, XOR, a full adder, anything — can be constructed using only NAND gates. NOR is also complete. This lets a silicon library offer a small set of primitives and still build everything.
Which gate is the heart of an adder and of parity logic, and why?
XOR. It outputs 1 exactly when its inputs differ, which is the sum bit of two bits (before carry) and toggles with each 1 in a parity chain.
Share your question in comments or talk to our mentor team for batch guidance.
Open this design in the free in-browser simulator — edit, compile and see the waveform/log instantly.
Learn Verilog with mentors, labs and placement support
This free series is maintained by the ChipXpert training team in Hyderabad & Bengaluru. Go deeper with instructor-led courses on real EDA tools.
Explore VLSI Courses