Logic circuit generator: Boolean expression to circuit
A logic circuit generator turns a Boolean expression into a gate diagram: every AND, OR, NOT and XOR in the expression becomes one gate, wired in the order the expression is evaluated. Type an expression below and its circuit appears, live and clickable, after the simulator has checked it on every row of the truth table. It doubles as a logic gate calculator: type A NAND B or (A + B)'C and click the inputs to read the output.
How the circuit is drawn
As written follows your expression exactly, one gate per operator:
- Each variable becomes an input switch, and the final operation drives the output
F. A'becomes a NOT gate. EveryA'in the expression shares the same inverter, as a real design would.- A NOT directly over an AND, OR or XOR becomes one NAND, NOR or XNOR gate:
(A + B)'is a single NOR. - Longer products and sums are chains of 2-input gates:
ABCis two AND gates. - The constants
0and1become ground and supply rails.
Simplified first reduces the function to its minimal sum of products with the Quine-McCluskey method, the same minimal form a Karnaugh map finds, then draws that. Variables the function does not depend on drop out of the circuit.
As written vs simplified
These counts come from the generator itself. Simplifying usually removes gates, but not always: a sum of products uses only AND, OR and NOT, so functions built from XOR are smaller as written.
| Expression | As written | Simplified |
|---|---|---|
| AB + AB' + A'B | 7 gates | A + B, 1 gate |
| A'B'C + A'BC + AB'C + ABC | 13 gates | C, no gates |
| A'B + AB' | 5 gates | AB' + A'B, 5 gates |
| (A + B)' | 1 gate (NOR) | A'B', 3 gates |
| (A XOR B) XOR C | 2 gates | 4 terms, 14 gates |
Worked example: F = AB + AB' + A'B
Drawn as written, this needs two inverters (for A' and B'), three AND gates (one per product) and two OR gates to add the three products: seven gates. Its truth table is 0, 1, 1, 1 for AB = 00, 01, 10, 11, which is exactly the OR gate. Click Simplified with this expression and the generator draws one OR gate. The algebra behind it, step by step, uses the Boolean laws: AB + AB' = A(B + B') = A, and A + A'B = A + B.
Writing expressions
| Operation | Type any of | Gate |
|---|---|---|
| AND | AB A*B A&B A AND B | AND |
| OR | A+B A|B A OR B | OR |
| NOT | A' !A ~A NOT A | NOT |
| XOR | A^B A XOR B | XOR |
| NAND, NOR, XNOR | A NAND B A NOR B A XNOR B | NAND, NOR, XNOR |
| Constants | 0 1 | ground, supply |
Variables are the single letters A to H, so AB means A AND B. NOT binds tightest, then AND, then XOR, then OR, so A + BC is A OR (B AND C); use brackets for anything else. The generator draws up to 6 variables and 24 gates; for bigger functions, simplify first or build in the lab. To list every row without a circuit, use the truth table generator, and to see the algebra, the Boolean simplifier.
From expression to working hardware
Every gate here is a real digiwleea part, built in the course from transistors: the NOT gate is two transistors and the NAND gate four. Open the circuit in the lab to go one level down, or follow how gates combine and truth table to circuit in the theory pages. The logic gate simulator is the place to try single gates first.
Frequently asked
How do you convert a Boolean expression to a logic circuit?
Work from the innermost operation outwards, in the order the expression is evaluated: NOT first, then AND, then OR. Each operator becomes one gate, each variable becomes an input wire, and the last operation's gate drives the output. For F = A'B + AB', invert A and B, feed A' with B into one AND gate and A with B' into another, then OR the two AND outputs.
How many gates does a Boolean expression need?
Drawn as written, one gate per operator, so A'B + AB' needs five: two NOT, two AND and one OR. The same function can often be drawn with fewer gates after simplification: AB + AB' + A'B needs seven gates as written but simplifies to A + B, a single OR gate.
Is the simplified circuit always smaller?
No. Simplified here means the minimal sum of products, an AND-OR circuit, found with the Quine-McCluskey method. That is the smallest two-level form, but some functions are smaller in another shape: (A XOR B) XOR C is two XOR gates as written and 14 gates as a sum of products.
Which operators can I type?
AND as AB, A*B, A&B or A AND B; OR as A+B, A|B or A OR B; NOT as A', !A, ~A or NOT A; XOR as A^B or A XOR B; and the words NAND, NOR and XNOR. 0 and 1 are constants. NOT binds tightest, then AND, then XOR, then OR, and brackets override the order.
Can I edit the generated circuit?
Yes. Open this circuit in the lab copies it into the digiwleea editor, where you can move gates, add more logic, run it, see its truth table or save it as a reusable part. Inside the embedded circuit you can already click the inputs to watch the output change.
How do I get a Boolean expression from a truth table?
Write one AND term for every row whose output is 1, with each variable plain if it is 1 in that row and inverted if it is 0, then OR the terms together. The truth table generator and the Karnaugh map solver on this site do this and simplify the result.
A Boolean expression and a circuit are two views of the same function. Read Boolean algebra to work with the expressions, or open the lab and build the circuit gate by gate.
Related tools: truth table generator, Boolean expression simplifier, Karnaugh map solver, truth table to expression converter and logic gate symbols and truth tables.
Open the lab →