Boolean Logic, Gates & Truth Tables
What is Boolean logic?
Boolean logic (named after George Boole) works with only two values: True (1) and False (0). A Boolean expression combines these values using operations like NOT, AND and OR. Every decision inside a computer — "is the password correct?", "is marks ≥ 33?" — finally becomes Boolean logic in electronic circuits called logic gates.
A room light controlled by two switches in series turns on only if switch 1 AND switch 2 are on. A doorbell with two buttons (front and back door) rings if button 1 OR button 2 is pressed.
Symbols used: NOT A is written A' or Ā; A AND B is A·B; A OR B is A + B; A XOR B is A ⊕ B.
Logic gates at a glance
NOT, AND, OR
NOT gate (inverter)
One input; the output is the opposite. Y = A'.
| A | Y = A' |
|---|---|
| 0 | 1 |
| 1 | 0 |
AND gate
Output is 1 only when all inputs are 1. Y = A·B. Think: "pass only if theory AND practical are cleared".
| A | B | Y = A·B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR gate
Output is 1 when at least one input is 1. Y = A + B. Think: "entry allowed with ID card OR fee receipt".
| A | B | Y = A + B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NAND and NOR (universal gates)
NAND = AND followed by NOT: Y = (A·B)'. Output is 0 only when both inputs are 1. NOR = OR followed by NOT: Y = (A + B)'. Output is 1 only when both inputs are 0.
| A | B | NAND (A·B)' | NOR (A+B)' |
|---|---|---|---|
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
They are universal: for example, connecting both inputs of a NAND gate together gives a NOT gate, because (A·A)' = A'. Chips are cheaper to make when only one kind of gate is used.
XOR (exclusive OR)
Output is 1 when the inputs are different. Y = A ⊕ B = A'B + AB'. Example: a staircase light with one switch at the bottom and one at the top — flipping either switch changes the light.
| A | B | Y = A ⊕ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
All truth tables with Python
In Python, the bitwise operators & (AND), | (OR) and ^ (XOR) work on 0 and 1, so we can print every table in a few lines:
print('A B | AND OR XOR NAND NOR')
for A in (0, 1):
for B in (0, 1):
AND = A & B
OR = A | B
XOR = A ^ B
print(A, B, '|', AND, ' ', OR, ' ', XOR, ' ', 1 - AND, ' ', 1 - OR)Boolean laws
| Law | AND form | OR form |
|---|---|---|
| Identity | A · 1 = A | A + 0 = A |
| Null (domination) | A · 0 = 0 | A + 1 = 1 |
| Idempotent | A · A = A | A + A = A |
| Complement | A · A' = 0 | A + A' = 1 |
| Involution (double NOT) | (A')' = A | |
| Commutative | A · B = B · A | A + B = B + A |
| Associative | (A · B) · C = A · (B · C) | (A + B) + C = A + (B + C) |
| Distributive | A · (B + C) = A·B + A·C | A + B·C = (A + B)(A + C) |
| Absorption | A · (A + B) = A | A + A·B = A |
Simplify Y = A·B + A·B'. → A·(B + B') (distributive) → A·1 (complement) → A (identity).
De Morgan’s laws
First law
- (A · B)' = A' + B'
- NOT of AND = OR of the NOTs
- NAND = "bubbled" OR
Second law
- (A + B)' = A' · B'
- NOT of OR = AND of the NOTs
- NOR = "bubbled" AND
Proof by truth table — check that both sides are equal for every row. Python can do all rows for us:
# Check De Morgan's laws for every combination
ok = True
for A in (False, True):
for B in (False, True):
law1 = (not (A and B)) == ((not A) or (not B))
law2 = (not (A or B)) == ((not A) and (not B))
print(A, B, law1, law2)
ok = ok and law1 and law2
print('Both laws hold:', ok)Logic circuits and expressions
A logic circuit joins gates together. To find its truth table, write the output expression and evaluate it for every input combination. Example: Y = (A·B) + C' — one AND gate, one NOT gate and one OR gate.
# Y = (A AND B) OR (NOT C)
print('A B C | Y')
for A in (0, 1):
for B in (0, 1):
for C in (0, 1):
Y = (A and B) or (not C)
print(A, B, C, '|', int(Y))Three inputs → 2³ = 8 rows. Y is 1 whenever C is 0, and also when A and B are both 1.
Summary & practice
- Boolean values: 0 and 1. Operations: NOT (A'), AND (A·B), OR (A+B), XOR (A⊕B).
- NAND and NOR are universal gates.
- n inputs → 2ⁿ rows in the truth table.
- De Morgan: (A·B)' = A' + B', (A+B)' = A'·B'.
1) Draw the truth table of Y = A' + B. 2) Simplify A + A'B. 3) Which gate gives 1 only when both inputs are 0?
Answers: 1) rows 00→1, 01→1, 10→0, 11→1. 2) A + B (using A + A'B = (A + A')(A + B)). 3) NOR.
