THRESHOLD
COMMON GROUND & BASIC LOGIC, FROM ONE WIRE TO A RUNNING PROGRAM
Thirteen chapters, with the actual truth tables and formulas, on why every computer only ever needs two voltages, how AND, OR, and NOT build every decision a program makes, how a chain of else-ifs and a classic FizzBuzz interview question put that logic to work, how binary numbers add and subtract with no minus sign in sight, why one well-placed IF beats a million comparisons, and how to trace a whole program, step by step, from its inputs to its consequences. Scroll to begin.
BEGIN — CHAPTER 01 →Before there's a 1 or a 0, there has to be a 0V everyone agrees on
Every voltage measurement is a comparison, not an absolute number. Saying a wire sits at 'five volts' only means something once everything else in the circuit agrees on what counts as zero — a shared reference point called ground. Every wire's voltage, high or low, is really just 'how far above ground.'
Digital logic uses that shared ground to draw a line. Anything close to ground reads as LOW — the digit 0. Anything close to the supply voltage reads as HIGH — the digit 1. A gap in between is deliberately left undefined, so a little electrical noise never flips a solid 0 into an accidental 1.
One wire only ever says yes or no. Enough wires say anything.
A single wire in Chapter 1's scheme carries exactly one bit — one yes-or-no, HIGH-or-LOW. On its own, that's not very expressive. But line up several wires, and every possible combination of their states becomes a distinct pattern — and everything a computer represents, numbers, letters, colours, sound, is just a name given to one of those patterns.
Add one more wire and the number of possible patterns doubles, because every pattern the old wires could make now happens twice — once with the new wire LOW, once HIGH. That doubling is the entire reason binary matters to anyone who isn't a mathematician: it's exactly what a real wire count buys you.
Every decision a computer makes reduces to three little circuits
A logic gate is a circuit with one job: look at its input voltages, and output HIGH or LOW according to a fixed rule. There are only a handful of these rules worth knowing, and just three of them — AND, OR, and NOT — are enough to build every other one, including every branch a program ever takes.
AND outputs HIGH only when both inputs are HIGH. OR outputs HIGH when at least one is. NOT simply flips whatever it's given. Pick a gate below, toggle the inputs, and watch it decide.
Two useful shortcuts fall out of combining AND, OR, and NOT
XOR ('exclusive or') outputs HIGH when its inputs disagree — exactly one HIGH, not both. It isn't a fourth fundamental gate; wire together an OR, an AND, and two NOTs and you get exactly the same truth table. XOR earns its own symbol only because it turns out to be exactly the circuit that adds two bits together, in Chapter 8.
De Morgan's laws are the other shortcut: negating an AND is the same as OR-ing the negations, and negating an OR is the same as AND-ing the negations. It's why 'not (raining and cold)' means exactly the same thing as 'not raining, or not cold' — in English or in silicon.
The word “if” is a logic gate wearing different clothes
Every plain-language connective maps onto one of Chapter 3's gates: “and” / “also” / “both” is AND; “or” / “either” is OR; “not” / “isn't” is NOT. Write “if raining or night, turn on the headlights” and you've already written an OR gate — you just haven't drawn it yet.
An if/then/else statement runs that gate's output through a fork in the road: take the THEN path when the condition reads HIGH, the ELSE path when it reads LOW. Nothing new is happening electrically — it's the same gate from Chapter 3, now deciding which of two instructions actually executes.
Real code rarely stops at one fork — it chains them
An if/else from Chapter 5 only picks between two paths. Most real decisions need more than two, so code chains conditions into a ladder: IF, then a series of ELSE IF, then a final ELSE as the catch-all. The computer checks each rung top to bottom and stops at the first one that reads HIGH — every rung below it is skipped entirely, even if it would also have been true.
A grading scale is the classic example: a score of 85 is technically also 'at least 70' and 'at least 60,' but only the first matching rung — 'at least 80' — assigns the grade. Order matters: swap the ladder's rungs and a 95 could accidentally be graded an F. Drag the score below and watch which rung wins.
Decimal counts by tens because we have ten fingers. Binary counts by twos because a wire has two states.
Decimal place value is powers of ten: the digit '3' in '300' means 3×10². Binary place value works identically, just with powers of two — each bit is worth twice its neighbour, so a HIGH bit contributes its position's power of two to the total, and a LOW bit contributes nothing.
That's the entire algorithm computers use to turn a row of wires into a number humans recognise: add up the powers of two for every bit reading HIGH. Toggle the bits below — they're already set to a famous number — and watch the decimal value update live.
Addition is XOR with a memory for what just overflowed
Adding two single bits needs two answers: the sum itself, and whether the result overflowed into the next column — a carry. XOR alone computes the sum (HIGH exactly when the two bits disagree, which is exactly binary addition without carrying), and AND alone computes the carry (only 1+1 overflows). That pairing is called a half adder.
A full adder just adds a third input — the carry arriving from the column before it. Chain enough full adders together, one per bit position, and you've built a circuit that adds numbers of any size, the same way every processor still does it today. Toggle two numbers below and watch it happen.
Chapter 6's ladder, run once per number, is a famous interview question
Modulo — the % operator — is the remainder left over after division: 10 % 3 is 1, because 3 goes into 10 three times with 1 left over. 'n is divisible by 3' is just shorthand for 'n % 3 equals 0.'
FizzBuzz, a famous programming-interview warm-up, is nothing more than Chapter 6's ladder run once per number: print 'FizzBuzz' if divisible by both 3 and 5, 'Fizz' if just 3, 'Buzz' if just 5, otherwise the number itself — and that double-check has to sit at the top of the ladder, or it never gets a turn. Drag N and watch the whole sequence recompute.
There's no separate subtractor circuit. There didn't need to be one.
Building a whole second circuit just for subtraction would be wasteful when Chapter 8 already built an adder. Two's complement solves this: flip every bit of a number and add 1, and the result behaves exactly like its negative in every calculation. Subtracting B from A becomes adding A to (−B) — the same adder, no new hardware.
The trick also gives negative numbers a home inside ordinary bits: with 4 bits, 0111 is +7 and 1000 is −8, with everything in between falling neatly into place, and the leftmost bit doubling as a sign flag — 0 for non-negative, 1 for negative — for free.
Guess smarter, not harder — one well-placed IF beats a million
Searching a sorted list the naive way checks every entry until one matches — worst case, N comparisons for a list of N items. Binary search does something smarter: check the middle entry with a single IF, and depending on whether it's too high or too low, throw away half the remaining list without even looking at it.
Each comparison halves what's left, which is Chapter 2's doubling formula run in reverse — so the worst case is just how many times you can halve N before reaching 1: log₂ N, rounded up. Drag the list size below and watch the gap between 'check everything' and 'check smartly' turn enormous.
Everything above is already a computer. It just needs a clock and a memory.
A register is a small row of circuits that can hold a pattern of bits steady — the computer's short-term memory. A clock is a signal that ticks at a steady rate, telling every register in the machine exactly when to accept a new value, so millions of gates change in lockstep instead of racing each other into nonsense.
And the branch from Chapter 5 becomes, in hardware, a multiplexer: a gate that looks at a condition and switches which of two wires actually reaches the next register. Every if-statement any program has ever run compiles down, eventually, to one of these, ticking on somebody's clock.
Read a program the way a computer does: one line, one consequence, at a time
Every chapter on this page is now sitting inside one small program — inputs, an AND, a branch, subtraction, a running total. Set the two inputs below, then press STEP to walk through it one line at a time and watch every variable change in real time.
This is the whole point of learning to read logic instead of just trusting it: given any starting condition, you can now predict — line by line, without running anything — exactly what comes out the other end.
“The design of this treatise is to investigate the fundamental laws of those operations of the mind by which reasoning is performed.”
GEORGE BOOLE, AN INVESTIGATION OF THE LAWS OF THOUGHT, 1854