Digital Circuits: Boolean Algebra, Multiplexers, Encoders and Decoders, Flip-Flops and Counters

The second sub-heading of Section A.2 names Boolean algebra, combinational circuits — multiplexers, encoders and decoders — and sequential circuits — flip-flops and counters. In a mechatronic system these are the logic between the sensors and the actuators: the interlock that stops a press, the decoder that selects a device, the counter that totals encoder pulses. GATE asks for a minimised expression, the output of a small circuit, the behaviour of a flip-flop on a clock edge, or the modulus and speed of a counter.
Overview

1. Boolean algebra and minimisation

1 min read · 4 parts
  • Identities: A + 0 = A, A · 1 = A, A + A = A, A + A′ = 1, A · A′ = 0, A + 1 = 1.
  • Absorption: A + AB = A and A(A + B) = A; also A + A′B = A + B.
  • De Morgan: (A + B)′ = A′B′ and (AB)′ = A′ + B′ — the reason NAND and NOR are each universal: either alone builds NOT, AND and OR.
  • Consensus: AB + A′C + BC = AB + A′C — the BC term is redundant because it is covered whichever value A takes.

A function is written as a sum of minterms (SOP) or a product of maxterms (POS). A Karnaugh map arranges the minterms in Gray-code order so that adjacent cells differ in one variable; grouping 1s in rectangles of 1, 2, 4 or 8 cells, wrapping round the edges, removes the variables that change within the group. Don’t-care cells may be counted as 1 when they enlarge a group. For F(A, B, C, D) = Σm(0, 2, 5, 7, 8, 10, 13, 15): the four corners (0, 2, 8, 10) form B′D′ and the centre block (5, 7, 13, 15) forms BD, so F = B′D′ + BD, the XNOR of B and D.

A function is written as a sum of minterms (SOP) or a product of maxterms (POS). A Karnaugh map arranges the minterms in Gray-code order so that adjacent cells differ in one variable…

2. Multiplexers, encoders and decoders

1 min read

A multiplexer routes one of 2ⁿ data inputs to its output under n select lines: a 32-to-1 MUX needs 5. It is also a universal function generator — a 2ⁿ-to-1 MUX implements any function of n variables by tying its data inputs to 0 or 1, and any function of n + 1 variables if the extra variable (or its complement) is allowed on the data inputs. A decoder has n inputs and 2ⁿ outputs, exactly one active: a 3-to-8 decoder with ABC = 101 (A the most significant) activates output 5. Because each output is one minterm, a decoder with an OR gate implements any function.

An encoder is the reverse: 2ⁿ inputs, one active, to an n-bit code. A plain encoder gives nonsense when two inputs are active at once, so the practical form is the priority encoder, which reports the highest-numbered active input and a valid flag: with D₁ and D₂ both high on a 4-to-2 priority encoder, the output is 10, for D₂. Half and full adders, comparators and code converters are the other combinational blocks; a combinational circuit has no memory, its output a function of the present inputs alone.

A multiplexer routes one of 2ⁿ data inputs to its output under n select lines: a 32-to-1 MUX needs 5. It is also a universal function generator — a 2ⁿ-to-1 MUX implements any function of n…

3. Latches and flip-flops

1 min read · 3 parts

A latch is level-sensitive: it follows its input while enabled. A flip-flop is edge-triggered: it samples at a clock edge and holds between edges, which is what makes synchronous design possible. The four types are defined by their characteristic equations.

Flip-flop characteristic equations
TypeNext state Q⁺Remark
SRS + R′Q, with SR = 0S = R = 1 is not allowed.
JKJQ′ + K′QJ = K = 1 toggles.
DDDelay: the output copies D at the edge.
TT ⊕ QT = 1 toggles, T = 0 holds.
🎯 Race-around, and the master–slave cure
A level-triggered JK latch with J = K = 1 toggles repeatedly for as long as the clock is high, ending in an unpredictable state — the race-around condition. A master–slave JK flip-flop lets the master respond while the clock is high and transfers to the slave only when it falls, so the output changes once per clock; an edge-triggered design achieves the same.
Latch versus flip-flop
Latch
  • Level-sensitive
  • Follows its input while enabled
Flip-flop
  • Edge-triggered
  • Samples at a clock edge, holds between

A latch is level-sensitive: it follows its input while enabled. A flip-flop is edge-triggered: it samples at a clock edge and holds between edges, which is what makes synchronous design…

4. Counters

1 min read · 2 parts

A counter of modulus N needs n flip-flops with 2ⁿ ≥ N: mod-10 (a decade counter) needs 4. In an asynchronous (ripple) counter each flip-flop is clocked by the previous one’s output, so the delays add: with n stages of delay t_pd, the output settles n·t_pd after the clock, and the maximum clock frequency is 1/(n·t_pd) — 10 MHz for four stages of 25 ns. Each stage halves the frequency, so an n-bit ripple counter divides by 2ⁿ: a 1 kHz clock gives 125 Hz at the third stage. A synchronous counter clocks every flip-flop together and uses gating to decide which toggle, so its speed is set by one flip-flop delay plus the gate delay, independent of length.

Shift-register counters trade flip-flops for simple decoding: an n-stage ring counter circulates a single 1 and has n states; a Johnson (twisted-ring) counter feeds back the complement of the last stage and has 2n states — 8 for four flip-flops. A mod-N counter from a binary counter is made by detecting state N and resetting, and up/down counters reverse the gating.

Ripple versus synchronous counter
Asynchronous (ripple)
  • Each stage clocked by the previous output
  • Delays add: settles after n·t_pd
  • f_max = 1/(n·t_pd)
Synchronous
  • All flip-flops clocked together
  • Gating decides which toggle
  • Speed independent of length
Ring versus Johnson counter
Ring counter
  • Circulates a single 1
  • n states
Johnson (twisted-ring)
  • Feeds back complement of last stage
  • 2n states: 8 for four flip-flops

A counter of modulus N needs n flip-flops with 2ⁿ ≥ N: mod-10 (a decade counter) needs 4. In an asynchronous (ripple) counter each flip-flop is clocked by the previous one’s output, so the…

Counters, Decoders and Frequency Division, Worked

2 min read · 2 parts

A ripple counter of n flip-flops divides the clock by 2ⁿ: eight flip-flops turn a 1 MHz clock into 1 000 000 / 256 = 3.906 kHz. To count modulo 10 four flip-flops are needed, since 2³ = 8 < 10 ≤ 16, with a gate that clears the count when it reaches 1010. A 3-to-8 decoder has 3 inputs and 8 outputs, one active at a time, and any Boolean function of three variables is the OR of the minterm outputs it contains. A 4-to-1 multiplexer with the inputs D₀ = 0, D₁ = 1, D₂ = 1, D₃ = 0 and select lines A, B realises the XOR of A and B. A priority encoder outputs the index of the highest-numbered active input: for an 8-to-3 encoder with inputs 2 and 5 active the output is 101.

Flip-flop behaviour
TypeNext state
DQ⁺ = D
TQ⁺ = T ⊕ Q
JKQ⁺ = JQ′ + K′Q; J = K = 1 toggles
SRS = R = 1 is forbidden
🧠 Worked: Gray code and the full adder
Binary to Gray: keep the most significant bit and XOR each bit with the bit above it, g(i) = b(i) XOR b(i+1). For 1011 the Gray bits are 1, 1 XOR 0 = 1, 0 XOR 1 = 1 and 1 XOR 1 = 0, so the code is 1110; going back, b(i) = g(i) XOR b(i+1) restores 1011. A full adder has S = A XOR B XOR Cin and Cout = AB + Cin(A XOR B). For A = B = Cin = 1, S = 1 and Cout = 1, and the check is 1 + 1 + 1 = 3 = binary 11. Two half adders and an OR gate build it. The usual slip is to write Cout = AB + Cin, which wrongly carries out when only Cin is 1.

A ripple counter of n flip-flops divides the clock by 2ⁿ: eight flip-flops turn a 1 MHz clock into 1 000 000 / 256 = 3.906 kHz. To count modulo 10 four flip-flops are needed, since 2³ = 8 <…

Key takeaways

  • De Morgan makes NAND and NOR universal; the consensus term BC in AB + A′C + BC is redundant.
  • K-map groups of 1, 2, 4, 8 wrap round the edges; the four corners of a 4-variable map are one group.
  • A 2ⁿ-to-1 MUX has n select lines; a decoder output is a minterm; a priority encoder reports the highest active input.
  • JK: Q⁺ = JQ′ + K′Q, toggling at J = K = 1; T: Q⁺ = T ⊕ Q; D: Q⁺ = D; master–slave removes race-around.
  • Mod-N needs 2ⁿ ≥ N; a ripple counter runs at most 1/(n t_pd) and divides by 2ⁿ; ring has n states, Johnson 2n.

Practice questions (24)

Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.

  1. By De Morgan’s theorem, (A + B)′ equals:

    1. A′B′
    2. A′ + B′
    3. AB
    4. A + B′
    Show answer

    Answer: A — A′B′

    The complement of a sum is the product of the complements: A + B is 0 only when both are 0, so (A + B)′ is 1 only when A′ and B′ are both 1. A′ + B′ is the complement of AB, the other half of the theorem.
  2. The expression AB + A′C + BC simplifies to:

    1. AB + A′C
    2. AB + BC
    3. A′C + BC
    4. B + C
    Show answer

    Answer: A — AB + A′C

    BC = BC(A + A′) = ABC + A′BC, and ABC is absorbed by AB while A′BC is absorbed by A′C, so BC adds nothing: the consensus theorem. B + C is wrong at A = 1, B = 0, C = 1, where the original is 0.
  3. The number of select lines required by a 32-to-1 multiplexer is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 5

    n select lines address 2ⁿ inputs, and 2⁵ = 32. The number of data inputs, 32, is not the number of select lines.
Show the other 21 questions
  1. The minimal sum-of-products form of F(A, B, C, D) = Σm(0, 2, 5, 7, 8, 10, 13, 15) is:

    1. B′D′ + BD
    2. B′D + BD′
    3. A′B′ + CD
    4. BD
    Show answer

    Answer: A — B′D′ + BD

    Minterms 0, 2, 8, 10 all have B = 0, D = 0 — the four corners of the map — giving B′D′; minterms 5, 7, 13, 15 all have B = 1, D = 1, giving BD. A and C take both values in each group and drop out. B′D + BD′ is the XOR, the complement of the answer.
  2. A 3-to-8 decoder with active-high outputs Y₀ to Y₇ receives inputs A = 1, B = 0, C = 1, with A the most significant bit. The output that goes high is Y____.

    Numerical answer — type the value.

    Show answer

    Answer: 5

    ABC = 101₂ = 4 + 0 + 1 = 5, so Y₅ is the one active output. Reading C as the most significant bit gives 101 again here, but 110 would then map to 3 instead of 6.
  3. A 4-to-2 priority encoder gives priority to the highest-numbered input. With D₁ = 1, D₂ = 1 and D₀ = D₃ = 0, its output Y₁Y₀ is:

    1. 10
    2. 01
    3. 11
    4. 00
    Show answer

    Answer: A — 10

    D₂ outranks D₁, so the code for 2, binary 10, is output. A plain encoder would OR the codes 01 and 10 and give 11, which names D₃, an input that is not active — the failure priority encoding exists to prevent.
  4. An edge-triggered JK flip-flop with J = 1 and K = 1 receives a clock edge. Its output:

    1. toggles
    2. is set to 1
    3. is reset to 0
    4. becomes indeterminate
    Show answer

    Answer: A — toggles

    Q⁺ = JQ′ + K′Q = Q′ + 0 = Q′: the state inverts. The indeterminate case belongs to the SR flip-flop with S = R = 1, which the JK design was made to replace.
  5. Which characteristic equations are correct?

    1. D flip-flop: Q⁺ = D
    2. T flip-flop: Q⁺ = T ⊕ Q
    3. JK flip-flop: Q⁺ = JQ′ + K′Q
    4. SR flip-flop: S = R = 1 is a permitted input that holds the state
    Show answer

    Answer: A — D flip-flop: Q⁺ = D; B — T flip-flop: Q⁺ = T ⊕ Q; C — JK flip-flop: Q⁺ = JQ′ + K′Q

    (A)–(C) are the defining equations. (D) False: S = R = 1 is the forbidden input of the SR flip-flop — both outputs are driven to the same value and the state after it is released is unpredictable. The hold input is S = R = 0.
  6. The minimum number of flip-flops needed to build a mod-10 counter is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 4

    n flip-flops give 2ⁿ states, and 2³ = 8 < 10 ≤ 16 = 2⁴, so four are needed, with six of the sixteen states unused. Ten would be the count for a ring counter, not a binary one.
  7. A 4-bit ripple counter is built from flip-flops each with a propagation delay of 25 ns. Allowing the counter to settle fully before the next clock edge, its maximum clock frequency is ____ MHz.

    Numerical answer — type the value.

    Show answer

    Answer: 10

    The worst-case settling time is 4 × 25 = 100 ns, since each stage waits for the one before it, so f_max = 1/100 ns = 10 MHz. Using a single delay gives 40 MHz, which is the synchronous counter’s figure (before gate delays).
  8. A Johnson (twisted-ring) counter built from four flip-flops has how many distinct states in its counting sequence?

    1. 8
    2. 4
    3. 16
    4. 15
    Show answer

    Answer: A — 8

    Feeding back the complement of the last stage fills the register with 1s and then with 0s: 0000, 1000, 1100, 1110, 1111, 0111, 0011, 0001 — 2n = 8 states. A ring counter has n = 4; a binary counter 2ⁿ = 16.
  9. Which statements are true?

    1. NAND gates alone can implement any Boolean function
    2. A 4-to-1 multiplexer can implement any function of three variables if one variable or its complement may be applied to the data inputs
    3. In a ripple counter all flip-flops are clocked simultaneously
    4. A master–slave JK flip-flop avoids the race-around condition
    Show answer

    Answer: A — NAND gates alone can implement any Boolean function; B — A 4-to-1 multiplexer can implement any function of three variables if one variable or its complement may be applied to the data inputs; D — A master–slave JK flip-flop avoids the race-around condition

    (A) NAND builds NOT (tied inputs), AND (NAND then NOT) and OR (by De Morgan).
    (B) Two variables drive the select lines and each data input is 0, 1, C or C′.
    (C) False: that is a synchronous counter; in a ripple counter each stage clocks the next.
    (D) The master and slave are enabled on opposite clock levels, so the output changes once per cycle.
  10. A 1 kHz square wave clocks a 3-bit ripple counter. The frequency of the output of the most significant flip-flop is ____ Hz.

    Numerical answer — type the value.

    Show answer

    Answer: 125

    Each toggling stage halves the frequency: 1000 → 500 → 250 → 125 Hz at the third stage, a division by 2³ = 8. Dividing by 3 confuses the number of stages with the division ratio.
  11. The Gray code of the binary number 1011 is

    1. 1110
    2. 1011
    3. 0100
    4. 1101
    Show answer

    Answer: A — 1110

    Keep 1, then 1 XOR 0 = 1, 0 XOR 1 = 1, 1 XOR 1 = 0, giving 1110; converting back recovers 1011. Leaving the code unchanged, 1011, is the tempting wrong option.
  12. The minimum number of 2-input NAND gates needed to realise a 2-input OR gate is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 3

    A + B = (A′ · B′)′: two NANDs with tied inputs make A′ and B′, and a third NAND combines them. Counting only one gate confuses OR with NAND, whose NOT-of-AND needs no inverters.
  13. A Johnson (twisted-ring) counter is built from six flip-flops. The number of distinct states in its counting sequence is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 12

    A Johnson counter has 2n states, so 2 × 6 = 12; a ring counter would have only 6, which is the tempting wrong count.
  14. The minimum number of flip-flops needed to build a mod-32 counter is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 5

    2⁵ = 32, so 5 flip-flops give exactly 32 states. Answering 32 treats each state as a separate flip-flop. Substituting the answer back into the relation confirms it.
  15. The minimal expression for F(A, B, C) = Σm(1, 3, 5, 7) is:

    1. B′C
    2. A + C
    3. A′C
    4. C
    Show answer

    Answer: D — C

    The four minterms are exactly those with C = 1 (the whole right half of the K-map), so F = C. The term A′C covers only minterms 1 and 3.
  16. A 3-variable odd-parity function F = A ⊕ B ⊕ C is implemented with an 8-to-1 multiplexer that uses A, B, C as select inputs. The number of data inputs that must be tied to logic 1 is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 4

    F = 1 for the minterms 1, 2, 4, 7 (odd number of ones), so exactly 4 data lines carry 1 and the other 4 carry 0. Answering 3 counts only the single-1 rows.
  17. The 4-bit Gray code word for the binary number 1011 is:

    1. 1110
    2. 1010
    3. 0110
    4. 1111
    Show answer

    Answer: A — 1110

    Keep the MSB and XOR each adjacent pair: 1, 1⊕0 = 1, 0⊕1 = 1, 1⊕1 = 0, giving 1110. The tempting 1010 copies the input and flips only the last bit.
  18. A mod-12 counter is driven by a 12 kHz clock. The frequency of the signal at its terminal-count output (one pulse per cycle), in kHz, is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 1

    A mod-N counter divides frequency by N: 12 kHz / 12 = 1 kHz. The value 12 multiplies instead of dividing. Substituting the answer back into the relation confirms it.
  19. The number of self-dual Boolean functions of 3 variables (those with f(x′) = (f(x))′ for every input) is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 16

    The 8 inputs form 4 complementary pairs; f is free on one member of each pair, so 2⁴ = 16. The total 2⁸ = 256 counts every function.
  20. An 8-bit ripple-carry adder uses full adders with a carry delay of 5 ns per stage and a sum-output delay of 8 ns after the last carry arrives. The worst-case time for the final sum bit, in ns, is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 43

    The carry must ripple through the first 7 stages (7 × 5 = 35 ns) before the last stage produces its sum 8 ns later: 43 ns. Using 8 × 5 + 8 = 48 counts one carry stage too many.
  21. The minimum number of literals in a minimal sum-of-products expression of F(A, B, C) = Σm(0, 1, 2, 5, 6, 7) is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 6

    The six 1-cells form a cycle with six 2-literal prime implicants and none essential; a minimal cover needs 3 of them, each with 2 literals, so 6 literals (for example A′B′ + BC′ + AC). Counting 12 adds all prime implicants.