Boolean Algebra and the Logic Inside Digital Circuits
Learn the rules of Boolean algebra, simplify expressions by hand, and see how logic gates combine to add binary numbers.
Key takeaways
- Boolean variables take only the values 0 and 1, combined with and, or and not.
- Several laws look like ordinary algebra, but others, such as x + x = x, do not.
- Any truth table can be turned into an expression and therefore into a circuit.
- A half adder uses one XOR gate and one AND gate to add two bits.
Boolean algebra is arithmetic with only two values, 0 and 1, and three basic operations: and, or, not. Digital circuits compute with exactly these, so an expression on paper corresponds to an arrangement of logic gates, and simplifying the expression can shrink the hardware.
The subject takes its name from George Boole, whose nineteenth-century work treated logic as a kind of algebra. In the 1930s Claude Shannon showed how this algebra could be used to analyze and design switching circuits.
The three operations
In circuit notation, x · y (often written xy) means "x and y", x + y means "x or y", and x′ means "not x". Read 1 as true or high voltage and 0 as false or low voltage.
| x | y | x · y | x + y | x′ |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Note that 1 + 1 = 1 here. The plus sign means inclusive "or", not addition. These are the tables of propositional logic with 0 and 1 in place of false and true.
The laws
| Law | "or" form | "and" form |
|---|---|---|
| Identity | x + 0 = x | x · 1 = x |
| Domination | x + 1 = 1 | x · 0 = 0 |
| Idempotence | x + x = x | x · x = x |
| Complement | x + x′ = 1 | x · x′ = 0 |
| Absorption | x + xy = x | x(x + y) = x |
| Distribution | x + yz = (x + y)(x + z) | x(y + z) = xy + xz |
| De Morgan | (x + y)′ = x′y′ | (xy)′ = x′ + y′ |
The two operations also commute and associate, and a double complement returns the original: (x′)′ = x.
Look at the columns. Swap + with · and swap 0 with 1, and each law turns into its partner. This is the principle of duality: if an identity follows from the basic laws, so does its dual.
The first distribution law would be false for ordinary numbers. In Boolean algebra you can confirm it: if x = 1, both sides are 1, and if x = 0, both sides equal yz. The last row is covered in detail in De Morgan's laws.
Simplifying an expression
Take F = xy + xy′ + x′y.
F = x(y + y′) + x′y factor x from the first two terms
= x·1 + x′y complement law
= x + x′y identity law
= (x + x′)(x + y) distribution of "or" over "and"
= 1·(x + y) complement law
= x + y identity law A circuit built directly from the first line needs two inverters, three AND gates and an OR step combining three signals. The final line needs one OR gate. Check a case: x = 0 and y = 1 gives 0 + 0 + 1 = 1 on the first line and 0 + 1 = 1 on the last.
Logic gates
A logic gate is a circuit whose output is a Boolean function of its inputs.
| Gate | Output is 1 when |
|---|---|
| AND | all inputs are 1 |
| OR | at least one input is 1 |
| NOT | the input is 0 |
| NAND | not all inputs are 1 |
| NOR | all inputs are 0 |
| XOR (two inputs) | the inputs differ |
| XNOR (two inputs) | the inputs match |
NAND is universal: you can build every other gate from it. A NAND with both inputs tied to x gives x′. Following a NAND with that inverter gives AND. Inverting x and y first and then applying NAND gives (x′y′)′, which equals x + y, so that is OR. NOR is universal too.
From a truth table to a circuit
Suppose a hypothetical voting light turns on when at least two of three switches a, b and c are on. The table has eight rows, and the output is 1 in four of them. Writing one "and" term for each gives the sum of products form:
F = a′bc + ab′c + abc′ + abc Since x + x = x, you may copy abc as often as you like and pair it with each other term. For instance, a′bc + abc = (a′ + a)bc = bc. Doing the same for the other two pairs gives:
F = ab + ac + bc That is three two-input AND gates feeding an OR. A graphical tool called a Karnaugh map finds such pairings by placing rows that differ in one variable next to each other. It works well up to about four or five variables; larger designs are minimized by software.
Adding binary numbers
Gates do arithmetic once numbers are written in base two, as described in binary numbers. Adding two bits a and b produces a sum bit and a carry bit.
| a | b | carry | sum |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
The sum column is a XOR b, and the carry column is a · b. That pair of gates is a half adder. A full adder also accepts a carry coming in. Its sum is a XOR b XOR c, and its carry out is ab + ac + bc, the voting circuit above. Chain full adders, one per bit position, and you can add binary numbers of any fixed length.
Each level is built from the one below it.
Choosing between inputs
Another everyday building block is the multiplexer, a circuit that picks one of several inputs. With data bits a and b and a select bit s, we want the output to equal a when s = 0 and b when s = 1.
M = s′a + sb Put s = 0: the expression becomes 1·a + 0·b = a. Put s = 1: it becomes 0·a + 1·b = b. The select bit acts like the points on a railway, steering one signal through and blocking the other.
A decoder does something related in reverse. Given a two-bit number, it switches on exactly one of four output lines, using the terms x′y′, x′y, xy′ and xy. For any input, precisely one of these is 1. Computers use circuits of this family to select a register or a memory location from an address.
With adders, multiplexers and a few gates for bitwise operations, you can sketch the core of an arithmetic logic unit, the part of a processor that calculates. All operations can be computed side by side, and a multiplexer then selects the result that was asked for.
What makes a good circuit
Fewer gates is only one goal. Designers also care about delay, which grows with the number of gates a signal must pass through one after another, and about power and chip area.
These goals can conflict. In the chain of full adders, each position waits for the carry from the one below, so a wide adder is compact but slow. A carry-lookahead design computes carries from the input bits using extra logic. It works out, for each position, whether that position generates a carry (a · b) or passes one along (a XOR b). The result uses more gates and finishes sooner.
Algebra supplies the many equivalent forms. Engineering decides which one is worth building.
Memory and time
Circuits whose output depends only on present inputs are called combinational. To remember something, a circuit feeds outputs back into inputs. Two cross-connected NOR gates form a simple latch that holds one bit. Circuits with memory are sequential, and a clock signal usually keeps their changes in step. Plain Boolean algebra describes each moment; describing behavior over time needs state machines as well.
Real gates also take a short time to respond, so two expressions that are equal in algebra can differ briefly in hardware. Engineers call the resulting blips hazards.
Don't-care cases
Sometimes certain inputs can never occur. If four bits encode a decimal digit from 0 to 9, the patterns for 10 through 15 are unused. A designer may treat their outputs as don't-cares and set each to whichever value gives the simpler expression.
For example, with bits d₃ d₂ d₁ d₀ (worth 8, 4, 2 and 1), suppose the output should detect the digits 8 and 9. Strictly, that is d₃d₂′d₁′. If patterns 10 to 15 never appear, the single variable d₃ is enough, because among the digits 0 to 9 only 8 and 9 have that bit set. The shortcut is safe only as long as the promise about the inputs holds, so careful designs check what happens if a forbidden pattern slips in.
The abstract view
A Boolean algebra, in general, is any structure with operations obeying these laws. The subsets of a set form one, with union as "or", intersection as "and" and complement as "not", the operations of basic set theory. Two values form the smallest interesting example. Every finite Boolean algebra has 2ⁿ elements for some n and matches the subsets of an n-element set.
Deciding whether a large Boolean expression can ever equal 1 is the satisfiability problem, central to chip checking and to formal verification in industry.
Try it yourself
- Show that x + x′y + y′ = 1. First, x′y + y′ = (x′ + y′)(y + y′) = x′ + y′. Then x + x′ + y′ = 1 + y′ = 1.
- Build XOR from AND, OR and NOT. One answer is xy′ + x′y: test all four input pairs.
- Simplify (x + y)(x + y′). Distribution gives x + yy′ = x + 0 = x.
- Write the dual of exercise 3 and check it: xy + xy′ = x.
For hands-on experiments, use a logic simulator or a low-voltage kit made for learners, and follow its safety instructions. Do not experiment with household mains power.