Mathematical logic · first circuits
Building useful circuits
Signal control, selection and routing, codes, comparison, adders and an ALU.
Toggle the inputs and follow the wires. In construction tasks, a completed table specifies exactly what your circuit must do: it is the task, not a hint.
Theory
Chapter 1
Build a condition from gates
The output of one gate can feed another gate. Simple rules then form a combined condition, such as permission without a stop signal.
Connect decisions
A permits the lamp; B stops it. First NOT reverses B. Then AND checks A and the NOT result.
Turn A on. Change B and follow the wire after NOT.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 |
A AND NOT B is a logical expression: a short way to write the circuit’s rule. Only A = 1, B = 0 turns the output on.
Three inputs: a pair or another way
First AND checks A and B. Then OR combines that result with C: the alternative path C can turn the lamp on by itself. Parentheses in (A AND B) OR C mark the first step.
Turn C off and find a case that turns Y on. Then turn C on and change A and B.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | C | Y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | |
| 0 | 1 | 0 | 0 | |
| 0 | 1 | 1 | 1 | |
| 1 | 0 | 0 | 0 | |
| 1 | 0 | 1 | 1 | |
| 1 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 |
At C = 1 the other inputs no longer affect Y. Three inputs give eight rows: check C = 0 and C = 1 for every A/B pair.
From gates to useful devices
Each circuit has a job. Start by changing one bit, then route data, read binary codes, compare and add numbers. Finally combine familiar operations in an ALU.
1. Control a signal and check data
Start with one extra control input and a chain of familiar XOR gates. Binary numbers are not needed yet.
Controlled inverter: keep or flip a bit
How can one circuit sometimes pass A through and sometimes invert it? S chooses the action: 0 keeps A; 1 flips it.
Toggle S without changing A. Then repeat with the other A value.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | S | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 |
A XOR 0 = A, while A XOR 1 = NOT A. XOR provides a controlled bit flip, useful later in arithmetic.
Parity: count the active ones
Y must be 1 when A, B and C contain an odd number of ones: one or three. With zero or two ones, Y = 0.
Turn on one input at a time: 000 → 100 → 110 → 111. Watch Y after each step.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | C | Y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | |
| 0 | 1 | 0 | 1 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 1 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 0 | |
| 1 | 1 | 1 | 1 |
Each added one flips the XOR chain’s result. A parity bit can detect any odd number of changed data bits, but not every error.
2. Select a source and a destination
Data and route selection are different inputs. First choose one of two sources, then route one source to different outputs.
Multiplexer: choose one of two inputs
How can a lamp receive A or B without moving wires? A third input S selects the route: 0 passes A; 1 passes B.
Keep A = 1 and B = 0. Toggle S. Then swap the input values and test the selection again.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | S | Y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 0 | |
| 0 | 1 | 0 | 0 | |
| 0 | 1 | 1 | 1 | |
| 1 | 0 | 0 | 1 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 |
NOT and two AND gates enable the required branch. OR joins its signal at Y. This is how a processor selects a data source.
Demultiplexer: route a single signal
Now there is one source D and two outputs. With S = 0, Y0 receives D; with S = 1, Y1 receives D. The other output stays zero.
With D = 1, change S: which lamp turns on? Then turn D off.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | D | S | Y0 | Y1 |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 1 | 0 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 |
S selects the receiver rather than the data value. This routes data or an enable signal to one device.
3. Encode a number with two bits
In a two-bit number, the high place has weight 2 and the low place has weight 1. Thus 00₂ = 0, 01₂ = 1, 10₂ = 2 and 11₂ = 3. A decoder selects a line from a code; an encoder returns the selected line’s code.
Decoder: two bits select one of four lines
S1 S0 gives the output number: 00 → Y0, 01 → Y1, 10 → Y2, 11 → Y3. Exactly one of the four outputs is 1.
Try all four codes. For each lit lamp, follow its pair of AND inputs.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | S1 | S0 | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 | |
| 0 | 1 | 0 | 1 | 0 | 0 | |
| 1 | 0 | 0 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 0 | 0 | 1 |
Each AND recognizes one two-bit combination. A decoder turns a binary address into a selected memory or device line.
Priority encoder: which request wins
D0…D3 are four requests. Y1 Y0 gives the active request’s number. If several are active, the highest index wins: D3, then D2, D1 and D0. Valid = 1 means at least one request is present.
Keep D1 on and add D3. Then turn every input off: how does code 00 without a request differ from D0?
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | D0 | D1 | D2 | D3 | Y1 | Y0 | Valid |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 | |
| 0 | 0 | 1 | 0 | 1 | 0 | 1 | |
| 0 | 0 | 1 | 1 | 1 | 1 | 1 | |
| 0 | 1 | 0 | 0 | 0 | 1 | 1 | |
| 0 | 1 | 0 | 1 | 1 | 1 | 1 | |
| 0 | 1 | 1 | 0 | 1 | 0 | 1 | |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | |
| 1 | 0 | 0 | 0 | 0 | 0 | 1 | |
| 1 | 0 | 0 | 1 | 1 | 1 | 1 | |
| 1 | 0 | 1 | 0 | 1 | 0 | 1 | |
| 1 | 0 | 1 | 1 | 1 | 1 | 1 | |
| 1 | 1 | 0 | 0 | 0 | 1 | 1 | |
| 1 | 1 | 0 | 1 | 1 | 1 | 1 | |
| 1 | 1 | 1 | 0 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Priority resolves simultaneous requests. Valid distinguishes request D0 with code 00 from no requests with that same code. This underlies interrupt arbitration.
4. Compare binary numbers
In A1 A0, A1 is the high bit and A0 the low bit. Toggle each input separately; the observation below the circuit shows both the binary representation and its numerical value.
Comparator: less, equal or greater
Compare A1 A0 and B1 B0, numbers from 0 to 3. Different high bits decide the result. Compare low bits only when the high bits match.
Compare 10 with 01, then 10 with 11. Finally make the two numbers equal.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A1 | A0 | B1 | B0 | A = B | A < B | A > B |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 | 0 | |
| 0 | 0 | 0 | 1 | 0 | 1 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 0 | 0 | 0 | 0 | 1 | |
| 0 | 1 | 0 | 1 | 1 | 0 | 0 | |
| 0 | 1 | 1 | 0 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 1 | 0 | 1 | 0 | |
| 1 | 0 | 0 | 0 | 0 | 0 | 1 | |
| 1 | 0 | 0 | 1 | 0 | 0 | 1 | |
| 1 | 0 | 1 | 0 | 1 | 0 | 0 | |
| 1 | 0 | 1 | 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 0 | 0 | 0 | 1 | |
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 | |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 |
XNOR tests matching bits. AND/OR branches combine the comparisons; exactly one output indicates A < B, A = B or A > B. A processor uses such results for branches.
5. Add from one place to several
The sum of two ones does not fit in one bit. Follow the outgoing carry, accept it from a neighbouring place, then connect these steps into a chain.
Half adder: why 1 + 1 gives 10
One bit can hold only 0 or 1. Adding two ones needs two places: Sum has weight 1 and Carry has weight 2.
Turn on both inputs. Then turn one off: compare Sum and Carry.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | Sum | Carry |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 0 | 1 | 1 | 0 | |
| 1 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 |
XOR computes the low bit Sum; AND computes Carry. Read Carry Sum from left to right: 10₂ = 1 × 2 + 0 × 1 = 2.
Full adder: accept an incoming carry
When adding multi-bit numbers, a carry arrives from the previous place. Cin is that extra bit. We now add A, B and Cin.
Start with three ones. Turn inputs off one at a time and watch the two result bits.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | Cin | Sum | Carry |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | 0 | |
| 0 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 0 | 1 | |
| 1 | 0 | 0 | 1 | 0 | |
| 1 | 0 | 1 | 0 | 1 | |
| 1 | 1 | 0 | 0 | 1 | |
| 1 | 1 | 1 | 1 | 1 |
Two XOR gates and carry logic produce a value from 0 to 3. Connecting one block’s Carry to the next block’s Cin adds multi-bit numbers.
Two-bit ripple adder: carry connects the places
Add A1 A0 and B1 B0. The low place adds A0 and B0; its carry enters the sum of A1 and B1. Read the result as Carry S1 S0, with weights 4, 2 and 1.
Start with 11 + 01: the carry reaches the high place. Then try 11 + 11, the largest sum.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A1 | A0 | B1 | B0 | S0 | S1 | Carry |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 1 | 1 | 0 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 1 | 0 | |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | |
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | |
| 0 | 1 | 0 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 0 | 1 | 1 | 0 | |
| 0 | 1 | 1 | 1 | 0 | 0 | 1 | |
| 1 | 0 | 0 | 0 | 0 | 1 | 0 | |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | |
| 1 | 0 | 1 | 0 | 0 | 0 | 1 | |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 | |
| 1 | 1 | 0 | 0 | 1 | 1 | 0 | |
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | |
| 1 | 1 | 1 | 0 | 1 | 0 | 1 | |
| 1 | 1 | 1 | 1 | 0 | 1 | 1 |
A half adder and a full adder form a chain. All three result bits are visible: 11₂ + 11₂ = 110₂, or 3 + 3 = 6. Larger adders propagate carry through more places.
6. Combine operations in an ALU
Now routing meets arithmetic: the instruction code chooses which result reaches the output. This block combines the circuits already explained above.
One-bit ALU: choose an operation
An arithmetic logic unit (ALU) performs different operations on the same inputs. Here A and B are one bit each; two instruction bits S1 S0 select AND, OR, XOR or addition.
Keep A = B = 1 and compare all four operations. For addition, inspect both Y and Carry.
How gates select the instruction
This is the actual computing circuit: its inputs are synchronized with the buttons above. Zoom controls let you inspect one gate or fit the whole circuit.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | S1 | S0 | Y | Carry |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 1 | 0 | 0 | |
| 0 | 0 | 1 | 0 | 0 | 0 | |
| 0 | 0 | 1 | 1 | 0 | 0 | |
| 0 | 1 | 0 | 0 | 0 | 0 | |
| 0 | 1 | 0 | 1 | 1 | 0 | |
| 0 | 1 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 1 | 1 | 1 | 0 | |
| 1 | 0 | 0 | 0 | 0 | 0 | |
| 1 | 0 | 0 | 1 | 1 | 0 | |
| 1 | 0 | 1 | 0 | 1 | 0 | |
| 1 | 0 | 1 | 1 | 1 | 0 | |
| 1 | 1 | 0 | 0 | 1 | 0 | |
| 1 | 1 | 0 | 1 | 1 | 0 | |
| 1 | 1 | 1 | 0 | 0 | 0 | |
| 1 | 1 | 1 | 1 | 0 | 1 |
Gates select the instruction too. In ADD mode, the low bit Y matches XOR, but Carry preserves the second one. This is a teaching one-bit ALU; a complete processor has more bits and operations.
Practice
Your own circuit
Tap a component to add it, or drag it onto the board. Connect a right-hand dot to another component’s left-hand dot: drag a wire or tap both dots in turn. Tap an input to toggle 0/1.
Keyboard and controls
Tab selects a component or port. Enter activates it. Arrow keys on a title move the component; Shift takes larger steps. Delete removes the selection, Esc cancels a wire. Ctrl/Cmd+Z undoes an edit.
? means the signal is unknown. Connect every input of the component.
On a narrow screen, pan the board by swiping its empty space. Only component titles and ports start a drag.
Tap a component to add it, or drag it onto the board. Connect a right-hand dot to another component’s left-hand dot: drag a wire or tap both dots in turn. Tap an input to toggle 0/1.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 |
Your own table: what should happen?
Change the “Wanted” column. Then build a circuit with the same output in every row.
Games
Permission and stop
A permits Y to turn on. B being on always turns Y off.
Add a gate → connect the dots → press Check. Toggle inputs to try cases.
Tap a component to add it, or drag it onto the board. Connect a right-hand dot to another component’s left-hand dot: drag a wire or tap both dots in turn. Tap an input to toggle 0/1.
Truth table
↗ “Show case” sets this row’s inputs on the circuit. The highlighted row matches the current inputs. This explores a case; it does not submit an answer. ? means an unknown signal.
| Show case | A | B | Y |
|---|---|---|---|
| 0 | 0 | ? | |
| 0 | 1 | ? | |
| 1 | 0 | ? | |
| 1 | 1 | ? |
What the circuit must do
Required is the specified output for each case. ↗ sets that case on your circuit.
| Show case | A | B | Required Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 |
↗ shows a case. 0 / 1 is your answer for that row.
Build your answer, then press Check. Every input combination is tested.