Boolean logic, named after the English mathematician George Boole, is a branch of algebra in which every variable can take only one of two values: true (1) or false (0). In the 1850s, Boole showed that logical reasoning could be expressed through mathematical equations. Today, Boolean algebra is the mathematical foundation of all digital circuits. Every operation performed by a computer, from adding two numbers to displaying an image, is ultimately implemented with circuits built from logic gates that obey the rules of Boolean algebra.
Boolean variables and the operations that act on them are the building blocks of the hardware inside the CPU. A variable that can hold either 0 or 1 is called a Boolean variable, and the operations used are AND, OR and NOT. From these three basic operations, all other gates and all complex digital systems can be constructed. Boolean expressions are also used inside programming languages; for example, the condition in an "if" statement evaluates to a Boolean value.
This chapter introduces the basic logic gates and their truth tables, the laws and identities of Boolean algebra, De Morgan's theorems, the concept of minterms and maxterms, and simple combinational circuits such as adders. Understanding Boolean logic prepares students to design circuits and to reason precisely about the conditions used in programs.
A Boolean variable is a symbol, such as A, B or C, that can represent either 0 (false) or 1 (true). Boolean operations combine one or more Boolean inputs to produce a Boolean output.
The NOT operation is a unary operation (it acts on a single variable). It inverts the input: NOT 0 = 1 and NOT 1 = 0. It is also called complementation or negation, and is written as A' or A-bar.
The AND operation produces output 1 only when all its inputs are 1; otherwise the output is 0. It is written as A . B or AB. In everyday terms, "A AND B is true only when both A and B are true".
The OR operation produces output 1 when at least one of its inputs is 1; the output is 0 only when all inputs are 0. It is written as A + B. In everyday terms, "A OR B is true when either A or B (or both) is true".
A logic gate is an electronic circuit that implements a Boolean operation. The main gates are NOT, AND, OR, NAND, NOR, XOR and XNOR.
The NOT gate has one input and one output. Its symbol is a triangle with a small bubble at the output.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
The AND gate has two or more inputs and one output.
| A | B | A . B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
The OR gate has two or more inputs and one output.
| A | B | A + B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
The NAND gate is the complement of AND. Its output is 0 only when all inputs are 1. It is a universal gate, meaning any logic circuit can be built using only NAND gates.
| A | B | NAND |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The NOR gate is the complement of OR. Its output is 1 only when all inputs are 0. It is also a universal gate.
| A | B | NOR |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
The XOR gate produces output 1 when the number of inputs equal to 1 is odd. For two inputs, output is 1 when exactly one input is 1. It is written as A XOR B.
| A | B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
The XNOR gate is the complement of XOR. Its output is 1 when both inputs are equal.
| A | B | XNOR |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Boolean algebra follows several important laws that help simplify expressions.
De Morgan's theorems relate the complement of a combination to the combination of complements: - (A . B)' = A' + B' - (A + B)' = A' . B'
In words, the complement of a product is the sum of the complements, and the complement of a sum is the product of the complements. De Morgan's theorems are extremely useful for simplifying logic circuits and for converting between NAND/NOR designs.
A Boolean expression is a combination of Boolean variables and operations, such as F = A . B + A'. A truth table for the expression lists the output for every combination of inputs. For an expression with n variables, the truth table has 2^n rows.
Expressions can be simplified using the laws above. For example, consider F = A . B + A . B'. Using the distributive law, F = A . (B + B'). Since B + B' = 1, we get F = A. So the expression A.B + A.B' simplifies to just A. Such simplification reduces the number of gates needed in a circuit, making it cheaper, faster and more reliable.
For n variables, each combination of inputs is a minterm. A minterm is written as a product (AND) of all the variables, with each variable complemented if its value is 0 and uncomplemented if its value is 1. For example, for two variables A and B, the minterm for the combination A=1, B=0 is A . B'. A Boolean function written as a sum of its minterms (SOP, Sum of Products) lists the minterms for which the output is 1.
A maxterm is written as a sum (OR) of all variables, each complemented if its value is 1 and uncomplemented if its value is 0. A function written as a product of its maxterms (POS, Product of Sums) lists the maxterms for which the output is 0. Both SOP and POS forms are standard ways to express a Boolean function from its truth table.
Combinational circuits are circuits whose output depends only on the current inputs, with no memory of past inputs.
A half adder adds two single bits A and B, producing a sum (S) and a carry (C). Its logic: - S = A XOR B - C = A AND B When both inputs are 1, the sum is 0 and the carry is 1.
A full adder adds three bits: A, B and a carry-in (Cin) from a previous stage. It produces sum and carry-out using XOR, AND and OR gates. Full adders are chained together to build multi-bit adders inside the ALU.
Boolean logic is not just for hardware; Python programs use it constantly. Python has the boolean type with values True and False, and operators and, or, not. A comparison expression evaluates to a Boolean value that can be used in conditions.
a = 5
b = 10
print(a < b and b < 20) # True and True = True
print(a > b or b > 20) # False or False = False
print(not (a == b)) # not False = True
Notice how the Python results match the truth tables: AND is True only when both operands are True, OR is True when at least one is True, and NOT inverts the value.
| A | B | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
| Law | AND Form | OR Form |
|---|---|---|
| Identity | A . 1 = A | A + 0 = A |
| Annulment | A . 0 = 0 | A + 1 = 1 |
| Idempotent | A . A = A | A + A = A |
| Complement | A . A' = 0 | A + A' = 1 |
| De Morgan | (A . B)' = A' + B' | (A + B)' = A' . B' |
Boolean logic provides the simple but powerful mathematics behind all digital electronics and every conditional statement in programming. Starting from just three operations, AND, OR and NOT, we can build every logic gate, simplify complex expressions with Boolean laws and De Morgan's theorems, and design useful circuits such as adders. The same ideas appear again in Python, where boolean values and the and, or, not operators control the flow of programs. With this foundation, we now move from how machines think to how humans think about solving problems systematically, the subject of the next chapter on problem solving.