Digital logic: gates, K-maps & flip-flops: practice problems with step-by-step solutions

Also called: Karnaugh maps · Boolean algebra · logic gates · sequential logic

Free Digital logic: gates, K-maps & flip-flops practice problems with diagrams, hints and full worked solutions. New values every time, at three levels: gates, truth tables and delays, Boolean algebra, K-maps and multiplexers, don't-cares, flip-flops and counters.

Free practice problemEasy
AF

NAND and NOR are universal gates: any logic function can be built from one of them alone. What is the minimum number N of 2-input NAND gates needed to build the NOT function shown?

F = A′

Exact answer: a whole number, no rounding.

Next problem →

What you practise

  1. Easygates, truth tables and delays
  2. MediumBoolean algebra, K-maps and multiplexers
  3. Harddon't-cares, flip-flops and counters

How to solve Digital logic: gates, K-maps & flip-flops problems

  1. For a circuit, work from the inputs to the output one gate at a time and write the value on every wire, or write its expression and fill in the truth table.
  2. For simplification, put the 1s (and the don’t-cares as X) into a Karnaugh map with Gray-code rows and columns: 00, 01, 11, 10.
  3. Cover the 1s with as few and as large groups of 1, 2, 4, 8 or 16 cells as possible, wrapping round the edges; each group is one product term made of the variables that stay constant. Group the 0s for the POS form.
  4. For flip-flops and counters, read the inputs at each active clock edge, write the state after every edge, and remember that an n-bit counter wraps round after 2ⁿ states.

Common mistakes

  • Ordering the K-map 00, 01, 10, 11 instead of the Gray code 00, 01, 11, 10.
  • Forgetting that groups may wrap round the edges, or drawing groups of 3 or 6 cells.
  • Covering don’t-cares that do not make a group bigger.
  • Forgetting the wrap-around of a counter, or reading Q₃Q₂Q₁Q₀ in the wrong order.

Key formulas

Basic gates
A·B, A + B, A′, (A·B)′, (A + B)′, A ⊕ B
Boolean rules
X + X′ = 1, X·X′ = 0, X + XY = X, XY + XY′ = X
De Morgan
(X·Y)′ = X′ + Y′, (X + Y)′ = X′·Y′
Karnaugh map order
00, 01, 11, 10 (Gray code)
Group of 2ᵏ cells
loses k variables
4-to-1 multiplexer
F = A′B′I0 + A′BI1 + AB′I2 + ABI3
Flip-flops
D: Q⁺ = D, T: Q⁺ = T ⊕ Q, JK: Q⁺ = JQ′ + K′Q
Counters
n-bit: 2ⁿ states; mod-N: smallest n with 2ⁿ ≥ N; fout = fclk/N
Ripple counter
fmax = 1/(n·tpd)
Ring and Johnson counters
n and 2n states

Learn Digital logic: gates, K-maps & flip-flops from scratch

Before this: Number systems

1Ones, zeros and gates

Digital circuits work with two values: 0 (low voltage, false) and 1 (high voltage, true). A logic gate takes one or more inputs and gives one output.

ABA·BANDABA + BORAA′NOT
  • AND gives 1 only when all inputs are 1. Written A·B or AB.
  • OR gives 1 when at least one input is 1. Written A + B.
  • NOT inverts: 0 becomes 1 and 1 becomes 0. Written A′ (or with a bar over A).
  • NAND and NOR are AND and OR followed by NOT; the small circle on a symbol means “inverted”.
  • XOR (A ⊕ B) gives 1 when the inputs differ.

A truth table lists the output for every combination of the inputs: 2ⁿ rows for n inputs. Row ABC = 101 is row number 5, called minterm m₅.

Self-check A = 1 and B = 0. What does a NAND gate output?
  1. 0
  2. 1
  3. It depends on the previous output
  4. Nothing: NAND needs both inputs to be 1

Answer: 1. AND of 1 and 0 is 0, and the NAND inverts it to 1. A NAND is 0 only when all its inputs are 1.

2Boolean algebra

Logic expressions follow rules like ordinary algebra, plus a few of their own. The most useful ones:

X + X′ = 1 X·X′ = 0 X + X = X X + X·Y = X
X·Y + X·Y′ = X De Morgan: (X·Y)′ = X′ + Y′, (X + Y)′ = X′·Y′

The combining rule X·Y + X·Y′ = X is the heart of simplification: two terms that differ in one variable merge, and that variable disappears.

A sum of products (SOP) is an OR of AND terms, such as F = AB′ + C. A product of sums (POS) is an AND of OR terms, such as F = (A + B)(B′ + C). Each product term is built from literals: variables, with or without a prime.

3Karnaugh maps

A Karnaugh map is a truth table drawn as a grid in which neighbouring cells differ in exactly one variable. That is why the rows and columns run 00, 01, 11, 10 (Gray code), not in binary order.

ABC00011110000103121140507161F = B
  1. Write a 1 in the cell of every minterm; the small number in each cell is its minterm number.
  2. Draw rectangles of 1, 2, 4, 8 or 16 cells around the 1s. Groups may wrap round the edges: the left and right columns are neighbours, and so are the top and bottom rows.
  3. Make every group as large as possible, and use as few groups as possible until every 1 is covered.
  4. Read each group as a product term: keep only the variables that do not change inside it. A group of 2ᵏ cells loses k variables.

In the map above the four 1s form one group. Inside it A changes and C changes, only B = 1 stays, so F = B.

Cells marked X are don’t-cares: input combinations that never occur. Use an X as a 1 when it makes a group bigger, and ignore it otherwise. Grouping the 0s instead gives the minimal POS form.

Self-check In a 4-variable map, how many literals does a group of 4 cells give?
  1. 1
  2. 2
  3. 3
  4. 4

Answer: 2. Four cells is 2², so two variables change inside the group and drop out. Of the four variables, two remain.

4A worked example

Follow every step. Try to predict the next one before you open it.

Worked example

Find the minimal SOP form of F(A, B, C) = Σm(0, 2, 4, 5, 6) and count its literals.

1

Fill the map

Rows A = 0, 1; columns BC = 00, 01, 11, 10. The 1s go in m0, m2 (row 0, columns 00 and 10) and m4, m5, m6 (row 1, columns 00, 01 and 10).

2

The biggest group

The columns BC = 00 and BC = 10 are neighbours across the edge. Together they hold m0, m2, m4 and m6: a group of four. Only C = 0 is constant, so this group is C′.

3

Cover the last 1

m5 (A = 1, BC = 01) is still uncovered. Pair it with its neighbour m4: in this pair A = 1 and B = 0 stay constant, so the term is AB′.

4

Read the answer

F = C′ + AB′

Three literals in two terms. Grouping m5 alone would give AB′C, a longer term: always make groups as large as possible, even if they overlap.

Answer

F = C′ + AB′, with 3 literals.

5Flip-flops and counters

Gates react to their inputs at once. A flip-flop stores one bit and only changes at the active edge of the clock (usually the rising edge).

  • D flip-flop: Q becomes D at every clock edge (Q⁺ = D).
  • T flip-flop: toggles when T = 1, holds when T = 0.
  • JK flip-flop: JK = 00 holds, 01 resets to 0, 10 sets to 1, 11 toggles.
CLKQ

A toggling flip-flop changes at every rising edge, so its output has half the clock frequency. Chaining n of them gives an n-bit binary counter with 2ⁿ states. A mod-N counter goes 0, 1, …, N − 1 and back to 0; it needs the smallest n with 2ⁿ ≥ N, and its last output runs at fclk/N.

In a ripple counter each stage is clocked by the one before it, so the delays add up: the clock period must be at least n·tpd. Shift-register counters use fewer states: a ring counter of n flip-flops has n states, a Johnson counter 2n.

Self-check A 4-bit binary up counter shows 13. Which count does it show after 5 more clock pulses?
  1. 18
  2. 2
  3. 3
  4. 8

Answer: 2. A 4-bit counter has 16 states and wraps from 15 to 0: 13 + 5 = 18, and 18 mod 16 = 2. Writing 18 forgets the wrap-around.

6Common mistakes

  • Writing the K-map columns as 00, 01, 10, 11. The order is Gray code: 00, 01, 11, 10.
  • Forgetting that groups wrap round the edges of the map.
  • Making groups of 3 or 6 cells. Groups have 1, 2, 4, 8 or 16 cells.
  • Covering a don’t-care that does not help: an X never has to be covered.
  • Reading a group by keeping the variables that change. Keep only the ones that stay constant.
  • Forgetting that a counter wraps round: an n-bit counter counts modulo 2ⁿ.

7How exam questions look

  • Easy: evaluate a gate circuit for given inputs, count the 1s of its truth table, place a minterm in a Karnaugh map, the number of NAND gates for a function, or the worst-case propagation delay.
  • Medium: simplify an expression, find the minimal SOP or POS form with a Karnaugh map, a function built with a multiplexer, or the isolated 1 of a map.
  • Hard: maps with don’t-cares, essential prime implicants, flip-flop timing diagrams, counters after many pulses, the number of flip-flops or the output frequency, and shift registers.

Check a simplified expression by testing one or two rows of the truth table: the original and the simplified form must give the same output.

Learn it step by step in the appLearn it step by step in the app

Worked examples

Example 1Easy
BAF

NAND and NOR are universal gates: any logic function can be built from one of them alone. What is the minimum number N of 2-input NAND gates needed to build the AND function shown?

F = A·B

Find N

Show hints
  1. A NAND gate with both inputs joined is an inverter.
  2. AND = NAND followed by an inverter; OR = NAND of the inverted inputs (De Morgan).
  3. Count every gate, including the ones used as inverters.
Show the answer and the step-by-step solution

Logic gates: each input and output is 0 or 1. AND gives 1 only when all inputs are 1; OR gives 1 when at least one input is 1; NOT inverts. NAND and NOR are AND and OR followed by NOT, and XOR gives 1 when the inputs differ. Work through a circuit from the inputs to the output, one gate at a time. A truth table lists the output for all 2ⁿ input combinations; the row number is the binary value of the inputs, so row ABC = 101 is minterm m₅.

Build it from NAND gates

De Morgan: A + B = (A′·B′)′, so an OR is a NAND of inverted inputs.

F = A·B = NOT(NAND(A, B))

Count the gates

N = 2

Answer

N = 2
Example 2Medium
ABCD00011110000111101111111

In this Karnaugh map exactly one 1 has no neighbouring 1, so it stays a group of one cell (a full minterm of four literals) in the minimal SOP form. Neighbours across the map edges count. Click that cell.

F = Σm(0, 3, 4, 10, 13, 14, 15)
  1. 1AB = 00, CD = 00
  2. 2AB = 00, CD = 01
  3. 3AB = 00, CD = 11
  4. 4AB = 00, CD = 10
  5. 5AB = 01, CD = 00
  6. 6AB = 01, CD = 01
  7. 7AB = 01, CD = 11
  8. 8AB = 01, CD = 10
  9. 9AB = 11, CD = 00
  10. 10AB = 11, CD = 01
  11. 11AB = 11, CD = 11
  12. 12AB = 11, CD = 10
  13. 13AB = 10, CD = 00
  14. 14AB = 10, CD = 01
  15. 15AB = 10, CD = 11
  16. 16AB = 10, CD = 10
Show hints
  1. Neighbouring cells differ in exactly one variable.
  2. The leftmost and rightmost columns are neighbours, and so are the top and bottom rows.
  3. Check the four neighbours (up, down, left, right, wrapping round) of every 1.
Show the answer and explanation

Karnaugh maps: the cells are ordered in Gray code (00, 01, 11, 10), so neighbouring cells, including the ones across the edges, differ in exactly one variable. Group the 1s in rectangles of 1, 2, 4, 8 or 16 cells, as large as possible and as few as possible, until every 1 is covered. Each group is one product term: the variables that stay constant inside it. A group of 2ᵏ cells loses k variables. Don't-cares (X) may be used to make groups bigger but never have to be covered. Grouping the 0s instead gives the minimal POS form.

Neighbours of each 1

A 1 with a neighbouring 1 can join a group of two or more.

m3: m2, m1, m7, m11 → 0
ABCD00011110000111101111111

The isolated 1

m3 = A′B′CD → AB = 00, CD = 11

Answer

AB = 00, CD = 11
Example 3Hard
TQ0​Q0​TQ1​Q1​TQ2​Q2​TQ3​Q3​CLKMOD-12

A synchronous mod-12 counter counts 0, 1, …, 11 and then returns to 0. It starts at 8. Which count Q (in decimal) does it show after 36 clock pulses?

Q0 = 836N = 12

Find Q

Show hints
  1. The counter has 12 states and repeats after 12 pulses.
  2. After k pulses the count is (8 + k) mod 12.
  3. 36 mod 12 = 0.
Show the answer and the step-by-step solution

Flip-flops and counters: a flip-flop changes only at the active clock edge. D copies its input (Q⁺ = D); T toggles when T = 1; JK holds for 00, resets for 01, sets for 10 and toggles for 11. An n-bit binary counter has 2ⁿ states and counts modulo 2ⁿ; a mod-N counter goes 0, 1, …, N − 1 and back to 0, and needs the smallest n with 2ⁿ ≥ N flip-flops. Each stage of a ripple counter halves the frequency, so the last output of a mod-N counter runs at fclk/N. A Johnson counter of n flip-flops has 2n states, a ring counter n.

Full cycles

Every 12 pulses bring the counter back to the same state.

36 = 3·12 + 0

Count after the remaining pulses

Q = (8 + 0) mod 12 = 8
Q = 1000₂

Answer

Q = 8

Questions and answers

What is Digital logic: gates, K-maps & flip-flops?

Digital circuits work with two values: 0 (low voltage, false) and 1 (high voltage, true). A logic gate takes one or more inputs and gives one output.

A truth table lists the output for every combination of the inputs: 2ⁿ rows for n inputs. Row ABC = 101 is row number 5, called minterm m₅.

How do I solve Digital logic: gates, K-maps & flip-flops problems step by step?
  1. For a circuit, work from the inputs to the output one gate at a time and write the value on every wire, or write its expression and fill in the truth table.
  2. For simplification, put the 1s (and the don’t-cares as X) into a Karnaugh map with Gray-code rows and columns: 00, 01, 11, 10.
  3. Cover the 1s with as few and as large groups of 1, 2, 4, 8 or 16 cells as possible, wrapping round the edges; each group is one product term made of the variables that stay constant. Group the 0s for the POS form.
  4. For flip-flops and counters, read the inputs at each active clock edge, write the state after every edge, and remember that an n-bit counter wraps round after 2ⁿ states.
What are common mistakes in Digital logic: gates, K-maps & flip-flops?
  • Ordering the K-map 00, 01, 10, 11 instead of the Gray code 00, 01, 11, 10.
  • Forgetting that groups may wrap round the edges, or drawing groups of 3 or 6 cells.
  • Covering don’t-cares that do not make a group bigger.
  • Forgetting the wrap-around of a counter, or reading Q₃Q₂Q₁Q₀ in the wrong order.
What do the Digital logic: gates, K-maps & flip-flops exercises cover?
  • Easy: gates, truth tables and delays
  • Medium: Boolean algebra, K-maps and multiplexers
  • Hard: don't-cares, flip-flops and counters

Every problem has new values, so you learn the method instead of an answer. Stuck? Open a small hint first, and the full explanation only when you need it.

How practising works

  • Every problem has new values, so you learn the method instead of an answer.
  • Stuck? Open a small hint first, and the full explanation only when you need it.
  • Your progress, mistakes and saved problems are kept, so you can review before the exam.

Topics before and after this one

Learn first

Courses with this topic

More topics in Electrical

Printable worksheet