Skip to content

Practice problems

Logic gates practice problems

A logic gate takes inputs that are each logic 0 (low) or logic 1 (high) and gives an output that's also 0 or 1, following a fixed rule, its truth table. These ten problems find gate outputs, count truth-table rows, evaluate Boolean expressions for given inputs, and finish by simplifying a circuit to fewer gates without changing its truth table. Type your answer to check it, and open the working whenever you want it.

The method

rows = 2n for n inputs
  • AND (A · B): 1 only when every input is 1. NAND is its complement (AND followed by NOT)
  • OR (A + B): 1 when any input is 1. NOR is its complement (OR followed by NOT)
  • NOT (Ā): inverts its single input
  • XOR (A ⊕ B): 1 when the inputs differ. XNOR gives 1 when they match
  • Operator precedence: brackets first, then NOT, then AND, then OR, as with × before + in ordinary maths

The problems

Type your answer and tap Check. Every one has the working, step by step.

  1. Problem 1 of 10

    A truth table lists the output for every combination of a circuit's inputs. How many rows does it have for a circuit with 4 inputs?

    Show the working
    1. Each input can be 0 or 1, and each extra input doubles the combinations: 2ⁿ rows for n inputs.
    2. 2⁴ = 2 × 2 × 2 × 2 = 16

    Answer: 16

  2. Problem 2 of 10

    A NAND gate has A = 1 and B = 1. What is its output? Type 0 or 1.

    Show the working
    1. NAND is AND followed by NOT.
    2. 1 AND 1 = 1, and NOT 1 = 0. NAND gives 0 only for this row.

    Answer: 0

  3. Problem 3 of 10

    An XOR gate has A = 1 and B = 0. What is its output? Type 0 or 1.

    Show the working
    1. XOR (A ⊕ B) gives 1 when its inputs differ.
    2. 1 and 0 differ, so the output is 1.

    Answer: 1

  4. Problem 4 of 10

    A NOR gate has A = 0 and B = 0. What is its output? Type 0 or 1.

    Show the working
    1. NOR is OR followed by NOT.
    2. 0 OR 0 = 0, and NOT 0 = 1. NOR gives 1 only when every input is 0.

    Answer: 1

  5. Problem 5 of 10

    How many 1s are in the output column of a 2-input OR gate's truth table?

    Show the working
    1. The four rows are 00, 01, 10 and 11. OR gives 1 when any input is 1.
    2. Only 00 gives 0, so the column has 3 ones. In logic, 1 OR 1 = 1.

    Answer: 3

  6. Problem 6 of 10

    Y = (A + B) · C̄, where + is OR, · is AND and C̄ is NOT C. What is Y when A = 0, B = 1 and C = 1? Type 0 or 1.

    Show the working
    1. Brackets first: A + B = 0 OR 1 = 1.
    2. C̄ = NOT 1 = 0.
    3. Y = 1 · 0 = 0

    Answer: 0

  7. Problem 7 of 10

    How many 1s are in the output column of a 3-input OR gate's truth table?

    Show the working
    1. 3 inputs give 2³ = 8 rows.
    2. OR is 0 only when every input is 0, which is one row: 000.
    3. 8 − 1 = 7 ones.

    Answer: 7

  8. Problem 8 of 10

    Y = A · B + C. In how many rows of its truth table is Y equal to 1?

    Show the working
    1. 3 inputs give 8 rows. Y is 1 when C = 1, or when A and B are both 1.
    2. C = 1 in 4 rows. With C = 0, only A = 1, B = 1 adds one more.
    3. 4 + 1 = 5 rows.

    Answer: 5

  9. Problem 9 of 10

    Stretch: Y = A · B + A · C is built from two AND gates and one OR gate. Factor out A using the distributive law, as in ordinary algebra. How many 2-input gates does the simpler circuit need?

    Show the working
    1. A is in both terms, so take it out: A · B + A · C = A · (B + C).
    2. That's one OR gate for B + C, then one AND gate with A.
    3. 2 gates instead of 3, with the same truth table.

    Answer: 2

  10. Problem 10 of 10

    Stretch: Y = (A + B) · (C + D). In how many of its 16 truth-table rows is Y equal to 1?

    Show the working
    1. Y is 1 only when both brackets are 1.
    2. A + B is 1 in 3 of the 4 combinations of A and B. C + D is the same, 3 of 4.
    3. Each of the 3 A, B combinations that make A + B = 1 pairs with each of the 3 C, D combinations that make C + D = 1: 3 × 3 = 9 rows.

    Answer: 9

Build it in a free lesson

“Logic gates” is lesson 2 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 43 before it first.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Logic gates” is lesson 2 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 43 before it first.

Or start from the very first lesson, no account needed

The ideas behind it

Questions people ask

How many rows does a truth table have?

One row for every combination of inputs. Each input can be 0 or 1, so each extra input doubles the count: n inputs give 2ⁿ rows. 2 inputs give 4 rows, 3 give 8 and 4 give 16.

What's the difference between OR and XOR?

OR gives 1 when any input is 1, including when both are. XOR, exclusive OR, gives 1 only when the inputs differ. They agree on every row but the last: for 1 and 1, OR gives 1 and XOR gives 0.

What do the symbols · and + and the bar mean?

In Boolean algebra, A · B means A AND B, A + B means A OR B, and a bar over a letter means NOT, so Ā is said "not A". The + isn't adding: in logic, 1 + 1 = 1. A ⊕ B is XOR.

More practice