LogicGates.org Open the simulatorSimulator

Truth table generator

Write a boolean expression in whatever notation you use, and get the full truth table as you type. Nothing is sent anywhere: it is all worked out in your browser.

& · ∧ and for AND, | + ∨ or for OR, ! ~ ¬ ′ not for NOT, ^ ⊻ xor for XOR. Adjacent letters like ab mean a AND b. For several outputs, separate the expressions with ; and name them: sum = a ^ b; carry = a & b.

Reading it as a ∧ b ∨ ¬c over 3 variables

abc Q
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Colours

True in 5 of 8 rows. As a simplified sum of products: ¬c ∨ a ∧ b  simplify this further

Truth tables of the seven basic gates

Every digital circuit is built from these. The rows count up in binary, the same as the table above.

ANDa ∧ b

ab Q
0 0 0
0 1 0
1 0 0
1 1 1

high only when both inputs are high

ORa ∨ b

ab Q
0 0 0
0 1 1
1 0 1
1 1 1

high when either input is high

XORa ⊻ b

ab Q
0 0 0
0 1 1
1 0 1
1 1 0

high when the inputs differ

NAND¬(a ∧ b)

ab Q
0 0 1
0 1 1
1 0 1
1 1 0

the inverse of AND

NOR¬(a ∨ b)

ab Q
0 0 1
0 1 0
1 0 0
1 1 0

the inverse of OR

NOT¬a

a Q
0 1
1 0

inverts its single input

XNOR¬(a ⊻ b)

ab Q
0 0 1
0 1 0
1 0 0
1 1 1

the inverse of XOR: high when the inputs match

AND, OR, NAND and NOR are not limited to two inputs in the simulator — give them as many as the circuit needs.

A worked example: the half adder

A circuit can have more than one output, and then it has one column per output. Adding two single bits gives a sum and a carry — the sum is XOR, the carry is AND. That is the whole half adder.

a b sum carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1

Read the last row: 1 + 1 is 0 carry 1, which is binary for 2. The generator above takes both outputs at once: open the half adder as one table or draw it as one circuit. Chain two half adders, then OR their two carry outputs together, and you have a full adder; chain four of those and you can add two four bit numbers.

From a circuit, not an expression

The generator above starts from algebra. The simulator goes the other way as well: build the circuit from real gates and it works out the table for you.

  1. Open the simulator and place an Input node for each variable and an Output node for each result, with your gates in between.
  2. Choose Build truth table from the toolbar. Every combination of inputs is evaluated and printed, including circuits with several outputs.
  3. To go backwards, start on an empty canvas and press ctrl+T. Fill in the outputs you want and the simulator builds a matching circuit out of gates.

Open the simulator

Questions

How do I write the expression?

Use whichever notation you are used to. AND can be written as a·b, a&b, a∧b, a AND b or just ab; OR as a+b, a|b, a∨b or a OR b; NOT as !a, ~a, ¬a, a’ or NOT a; XOR as a^b, a⊻b or a XOR b. Brackets work as you would expect, and 0 and 1 are constants.

Can the table have more than one output?

Yes. Separate the expressions with semicolons and name each one, as in "sum = a ^ b; carry = a & b". The table gets one column per output, all over the same inputs, so the rows line up the way they would for a real circuit. The circuit diagram generator takes the same syntax and draws every output.

How many variables can it handle?

Up to 8, which is a table of 256 rows. Single letters are variables, so "abc" means a AND b AND c.

How is the table ordered?

Rows count up in binary from all zeros to all ones, with the first variable as the most significant bit. That is the conventional ordering, so the table matches the one in your textbook.

Can I get a circuit out of a truth table?

Yes, in the simulator. Open it on an empty canvas and press ctrl+T (or cmd+T), fill in the output column, and it builds a working circuit of real gates that matches your table.