Uni-Sine
Computer ScienceData and logic

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.

Try it

Logic Gate Simulator

Wire up logic gates and watch the signals flow

Go to its page

How to use the logic gate simulator

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Read the truth table. The row your switches are on now is highlighted, and the expression for each lamp is underneath.

The six gates

ABANDORNANDNORXOR
0000110
0101101
1001101
1111000

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:

ABSumCarry
0000
0110
1010
1101

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.

practice
Pick an answer, then check it.
A = 1 and B = 1 go into an XOR gate. Its output goes into a NOT gate. What comes out?

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?
A program where you connect logic gates to inputs and outputs and test the circuit, seeing every signal and the truth table without building it.
How do I make a truth table for my circuit?
Build it in the simulator with a switch for each input and a lamp for each output. The truth table appears beside the circuit and updates as you wire.
What is a half adder?
A circuit that adds two bits: XOR gives the sum and AND gives the carry.
Why is NAND called a universal gate?
Because NOT, AND, OR and every other gate can be built from NAND gates alone. The simulator's XOR from four NANDs is one example.
Can the simulator do sequential circuits?
Yes, simple ones. It has a clock input, and you can build an SR latch from two NOR gates, which its truth table marks as keeping its value.

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
Read next
Computer Science · Computer systemsWhat is a logic gate? Types, truth tables and symbolsWhat a logic gate is, the 7 types with truth tables, how gates combine into circuits and adders, Boolean notation, and a free simulator to try them.