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
- 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.
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
- Each input can be 0 or 1, and each extra input doubles the combinations: 2ⁿ rows for n inputs.
- 2⁴ = 2 × 2 × 2 × 2 = 16
Answer: 16
Problem 2 of 10
A NAND gate has A = 1 and B = 1. What is its output? Type 0 or 1.
Show the working
- NAND is AND followed by NOT.
- 1 AND 1 = 1, and NOT 1 = 0. NAND gives 0 only for this row.
Answer: 0
Problem 3 of 10
An XOR gate has A = 1 and B = 0. What is its output? Type 0 or 1.
Show the working
- XOR (A ⊕ B) gives 1 when its inputs differ.
- 1 and 0 differ, so the output is 1.
Answer: 1
Problem 4 of 10
A NOR gate has A = 0 and B = 0. What is its output? Type 0 or 1.
Show the working
- NOR is OR followed by NOT.
- 0 OR 0 = 0, and NOT 0 = 1. NOR gives 1 only when every input is 0.
Answer: 1
Problem 5 of 10
How many 1s are in the output column of a 2-input OR gate's truth table?
Show the working
- The four rows are 00, 01, 10 and 11. OR gives 1 when any input is 1.
- Only 00 gives 0, so the column has 3 ones. In logic, 1 OR 1 = 1.
Answer: 3
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
- Brackets first: A + B = 0 OR 1 = 1.
- C̄ = NOT 1 = 0.
- Y = 1 · 0 = 0
Answer: 0
Problem 7 of 10
How many 1s are in the output column of a 3-input OR gate's truth table?
Show the working
- 3 inputs give 2³ = 8 rows.
- OR is 0 only when every input is 0, which is one row: 000.
- 8 − 1 = 7 ones.
Answer: 7
Problem 8 of 10
Y = A · B + C. In how many rows of its truth table is Y equal to 1?
Show the working
- 3 inputs give 8 rows. Y is 1 when C = 1, or when A and B are both 1.
- C = 1 in 4 rows. With C = 0, only A = 1, B = 1 adds one more.
- 4 + 1 = 5 rows.
Answer: 5
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
- A is in both terms, so take it out: A · B + A · C = A · (B + C).
- That's one OR gate for B + C, then one AND gate with A.
- 2 gates instead of 3, with the same truth table.
Answer: 2
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
- Y is 1 only when both brackets are 1.
- A + B is 1 in 3 of the 4 combinations of A and B. C + D is the same, 3 of 4.
- 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
“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.
“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 neededThe ideas behind it
- Logic gates explainedAND, OR, NOT, XOR and their inverted forms: each one's rule is a truth table.
- How to make a truth tableEvery input combination and its output: the complete, unarguable description of a logic circuit.
- Boolean algebra rules, with worked examplesThe handful of laws that simplify any logic expression, and how to turn a truth table into gates.
- What is an XOR gate?1 when the inputs differ, 0 when they match: the gate behind stair lights, adders and parity bits.
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
- Ohm's law practice problemsFind V, I or R, then the power, with the working for each.
- Units and prefixes practice problemsConvert mA, kΩ, µF, nF, pF, ms and mV, with the working for each.
- LED resistor practice problemsSize the resistor for one LED or a string, round to a standard value, check the power.
- Electrical power practice problemsPower three ways, energy in kWh, battery life and running costs, all worked.
- Series and parallel resistors practice problemsTotals in series and parallel, mixed networks and branch currents, all worked.
- Kirchhoff's laws practice problemsBalance currents at a junction and voltages round a loop, with the working for each.
- Voltage divider practice problemsFind Vout, pick R2 for a target and work out loading, with the working for each.
- Thevenin and Norton equivalent practice problemsReduce a network to V_th in series with R_th, then load it, with the working.
- Capacitor practice problemsCharge, capacitance, series and parallel, and stored energy, with the working.
- RC time constant practice problemsτ = R × C, the 63% rule, charging and discharging, with the working.
- Inductor practice problemsV = L × ΔI ÷ Δt, stored energy and inductors in series and parallel, with the working.
- RL circuit time constant practice problemsτ = L ÷ R, the current's rise and decay, and inductive kickback, with the working.
- AC voltage and transformer practice problemsPeak, RMS, period, AC power and transformer turns ratios, with the working.
- Capacitive and inductive reactance practice problemsCapacitive and inductive reactance, AC current and impedance, with the working.
- Impedance practice problems for RC and RL circuitsSeries RC and RL impedance, phase angle and current, with the working.
- RC filter practice problemsCutoff frequency, choosing R or C, and the output either side of the cutoff, with the working.
- Decibel practice problemsRatios to dB and back, for power and voltage, gains that add and the −3 dB point.
- LC resonance practice problemsf₀ = 1 ÷ (2π√(LC)), tuning for a frequency, and scaling, with the working.
- Diode practice problemsForward voltage, series resistor current, diodes in series, reverse bias and power dissipation.
- Rectifier and ripple practice problemsPeak output, ripple and the smoothing capacitor for half-wave and bridge rectifiers.
- Zener diode practice problemsSize a Zener regulator's resistor, split its current and check the Zener's power.
- Transistor switch practice problemsBase current, base resistor and load current for a BJT switch, then a MOSFET.
- MOSFET switch practice problemsConduction loss from R_DS(on), gate and pull-down currents, flyback diodes and junction temperature.
- Op-amp gain practice problemsInverting and non-inverting gain, the output, the resistor to pick and when it clips.
- Inverting and summing amplifier practice problemsInverting gain, input resistance, summing amps, averaging, a simple DAC and clipping.
- Schmitt trigger and hysteresis practice problemsHysteresis band, both thresholds and the feedback resistor for a comparator.
- Op-amp limits practice problemsGain-bandwidth, slew rate, output swing and input offset, with the working.
- Binary and hex practice problemsBinary to decimal and back, bits needed, the largest n-bit number and hex.
- Counters and flip-flops practice problemsTop count, flip-flops needed, frequency division, rollover and ripple delay.
- PWM and duty cycle practice problemsDuty cycle, average voltage, on-time, analogWrite 0–255 and power, with the working.
- ADC and analog input practice problemsanalogRead to volts and back, resolution, dividers and 12-bit ADCs, with the working.