Logic gate simulator with a live truth table
A logic gate simulator lets you wire up logic gates on screen and test the circuit by flipping its inputs, instead of building it from chips. Our logic gate simulator has AND, OR, NOT, NAND, NOR and XOR gates, switches, a clock and lamps. Drag gates onto the board, pull wires between their pins, flip the switches and watch the signals move through one gate at a time. Beside the circuit, a truth table of every input combination and a Boolean expression for each lamp update as you wire.
Logic Gate Simulator
Wire up logic gates and watch the signals flow
How to use the logic gate simulator
- Open the Logic Gate Simulator. It opens on a half adder. Load another ready-made circuit from Circuits: a full adder, an SR latch, a 2-to-1 multiplexer, XOR from four NANDs, a majority vote, or a clock and gate.
- Drag a gate, a switch, a clock or a lamp from the palette onto the board. The board takes up to 30 parts and 60 wires.
- Drag from a part's output pin to another part's input pin to wire them. Click a wire to select it, or drag its end off a pin to disconnect it. Select a part and press Delete to remove it.
- Under Run, flip each switch, such as A = 0 or A = 1, and press play to watch the signals move through the circuit, one gate delay at a time.
- Read the truth table. The row your switches are on now is highlighted, and the expression for each lamp is underneath.
The six gates
| A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
NOT has a single input and gives the opposite value. AND needs both of its inputs on to switch on, OR needs at least one, and XOR exactly one. NAND and NOR are AND and OR followed by NOT. In the simulator's expressions, A·B means A AND B, A + B means A OR B, A ⊕ B means A XOR B, A′ means NOT A, and ↑ means NAND.
Circuits to build and test
The half adder
The opening circuit adds two bits. An XOR gate gives the sum and an AND gate the carry, so the lamps read Sum = A ⊕ B and Carry = A·B:
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The last row is 1 + 1 = 10 in binary: a sum of 0 and a carry of 1. Load the Full adder to add a carry in as well: its carry out is (A ⊕ B)·Cin + A·B, and chaining full adders adds numbers of any length.
XOR from four NAND gates
Load XOR from four NANDs. Its truth table matches XOR exactly: 0, 1, 1, 0. NAND gates can be combined to make every other gate, which is why chips are often built from them; the Nand2Tetris course builds a whole computer starting from NAND alone.
A majority vote
Three people vote with switches A, B and C, and the lamp lights if at least two say yes. Load Majority vote: the expression is A·B + B·C + A·C, and the truth table has the lamp on in exactly the 4 rows with two or three 1s.
An SR latch: memory
Load SR latch: two NOR gates, each feeding the other. Set S = 1 and Q turns on; set R = 1 and it turns off. With both at 0, the truth table says keeps: Q stays at whatever it was last. The circuit remembers one bit, which is the start of computer memory. Because it has a loop, the simulator shows no single expression for its lamps.
Build your own
Clear the board and build NOT(A AND B) with an AND gate and a NOT gate. Check that its truth table is the same as a single NAND gate: 1, 1, 1, 0.
Try a question on predicting a gate's output, then press Mark to check your answer in the Circuits course.
Predict a logic gate's output from its inputs.
Press Mark to have your answer marked in the Circuits course.
What the simulator doesn't do
- Gates with more than two inputs. Chain two-input gates instead: A AND B AND C is (A AND B) AND C.
- Chips such as counters, decoders or registers, and flip-flops other than the latch you build yourself.
- Big tables. The truth table covers up to 6 inputs, which is 64 rows.
- Simplifying expressions. It shows each lamp's expression as wired. To simplify one, use the Boolean algebra calculator.
Common mistakes
- Mixing up OR and XOR. OR is 1 when both inputs are 1; XOR is 0.
- Wiring two outputs together. Each input takes one wire. To combine two signals, use a gate.
- Missing rows in a truth table. n inputs give 2ⁿ rows: 3 inputs make 8.
- Forgetting NAND is not AND. It is the opposite of AND on every row.
Common questions
What is a logic gate simulator?
How do I make a truth table for my circuit?
What is a half adder?
Why is NAND called a universal gate?
Can the simulator do sequential circuits?
Revision cards
Read the front, say your answer, then flip to check.
Where to go next
- Solve it
Logic Gate Simulator
Wire up logic gates and watch the signals flow
Open the tool - Learn it
Circuits
Resistors, capacitors and logic gates: build and understand real circuits
Start the course - Test it
AP Computer Science Principles
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper