Logic Gates

Logic gates are the atoms of digital electronics. Learn binary signals and logic levels, the basic gates (NOT, AND, OR, NAND, NOR, XOR, XNOR) with truth tables and symbols, universal gates, CMOS implementation, noise margins, fan-out, propagation delay and dynamic power.

Digital circuits represent information with two voltage levels — LOW (0) and HIGH (1). Gates combine these according to Boolean rules. Billions of gates, built from CMOS transistors, make up every processor and memory chip.

An analogy

Gates are like simple decision rules: AND = 'only if both switches are on', OR = 'if either switch is on', NOT = 'the opposite'.

Truth tables

A truth table lists the output for every input combination (2ⁿ rows). AND is 1 only when all inputs are 1; OR is 1 when any input is 1; XOR is 1 when inputs differ; NAND/NOR are inverted AND/OR.

Universal gates and CMOS

Any logic function can be built from NAND alone (or NOR alone). In CMOS, a NAND is two PMOS in parallel (pull-up) and two NMOS in series (pull-down) — naturally inverting gates are the cheapest.

Electrical characteristics

Logic families (TTL, LVTTL, LVCMOS 3.3/1.8 V) define voltage thresholds. Noise margins tell how much noise a signal can tolerate. Fan-out is how many inputs one output can drive; t_pd is the delay from input change to output change.

Power

CMOS draws power mainly when switching: P = αCV²f, plus leakage in modern nanometre processes. Lowering V_DD is the most effective way to cut power (quadratic).

Formulas

Worked example: Noise margins (LVTTL)

Given: V_OH 2.4 V, V_IH 2.0 V, V_IL 0.8 V, V_OL 0.4 V

Find: NM_H, NM_L.

Answer: 0.4 V each

Worked example: Dynamic power

Given: C = 10 pF, V_DD = 3.3 V, f = 10 MHz, α = 0.5

Find: P.

Answer: ≈ 0.54 mW

Gates in Verilog

module gates (
  input  wire a, b,
  output wire y_and, y_or, y_not, y_nand, y_nor, y_xor, y_xnor
);
  assign y_and  = a & b;
  assign y_or   = a | b;
  assign y_not  = ~a;
  assign y_nand = ~(a & b);
  assign y_nor  = ~(a | b);
  assign y_xor  = a ^ b;
  assign y_xnor = ~(a ^ b);
endmodule

Hardware description languages describe gates with bitwise operators. Synthesis tools turn these into real gates or FPGA look-up tables.

Common mistakes

Applications

Key takeaways

Going further