Section 03 · Practice Questions

Digital Logic Circuits & Gate Conversions

Thirteen questions that build classic digital blocks in ladder logic — comparators, multipliers, subtractors, decoders, a binary-to-BCD converter, seven-segment logic, flip-flops, and conversions to NAND-only and NOR-only universal-gate form.

13Questions
13Worked Solutions
All practice sections

Build the truth table and simplified equation first, then turn it into the ladder program — attempt each fully before opening the worked solution.

Q1

A 2-bit equality comparator in ladder logic

Design a simplified ladder program for a 2-bit comparator handling the case A = B, where A and B are each two-bit numbers. Build the truth table first, then draw the simplified circuit.

ShowHide worked solution

Let A = A₁A₀ and B = B₁B₀. The two numbers are equal when each bit matches: A₁ = B₁ and A₀ = B₀. The equality of two bits is the XNOR function, X ⊙ Y = XY + X′Y′.

F = (A₁ ⊙ B₁) · (A₀ ⊙ B₀) = (A₁B₁ + A₁′B₁′) · (A₀B₀ + A₀′B₀′)

Each XNOR is a pair of parallel branches; the two XNORs are wired in series so the coil energises only when both bit-pairs match.

Ladder program
|--[ A1]--[ B1]--+--[ A0]--[ B0]--+----( F )--|
|                |                |
|--[/A1]--[/B1]--+--[/A0]--[/B0]--+

Two XNOR networks in series — F is ON only when A = B.

Final AnswerF = (A₁B₁ + A₁′B₁′)(A₀B₀ + A₀′B₀′) — two bit-wise XNORs wired in series into one coil.
Q2

A 2-bit binary multiplier

Design a 2-bit multiplier circuit and write down its simplified Boolean equations.

ShowHide worked solution

Multiplying A = A₁A₀ by B = B₁B₀ gives a product P of up to four bits, P₃P₂P₁P₀. The four AND-gate partial products are added column by column.

P₀ = A₀·B₀ P₁ = A₁B₀ ⊕ A₀B₁ C₁ = (A₁B₀)·(A₀B₁) P₂ = A₁B₁ ⊕ C₁ P₃ = (A₁B₁)·C₁

So the circuit needs four AND gates for the partial products, one half-adder to produce P₁ and the carry C₁, and a second half-adder to produce P₂ and P₃.

Final AnswerP₀ = A₀B₀; P₁ = A₁B₀ ⊕ A₀B₁ with carry C₁ = A₁B₀·A₀B₁; P₂ = A₁B₁ ⊕ C₁; P₃ = A₁B₁·C₁.
Q3

A full subtractor built from NAND gates only

Realise a full subtractor using only 2-input NAND gates. Show the truth table, the simplified Boolean equations and the corresponding NAND-only circuit.

ShowHide worked solution

Inputs are A (minuend), B (subtrahend) and Bin (borrow-in); outputs are D (difference) and Bout (borrow-out).

Full-subtractor truth table.
ABBinDBout
00000
00111
01011
01101
10010
10100
11000
11111
D = A ⊕ B ⊕ Bin Bout = A′·B + A′·Bin + B·Bin

Building it from NAND only

Every gate is replaced by its NAND equivalent: X′ = X NAND X; X·Y = (X NAND Y) NAND (X NAND Y); X+Y = (X NAND X) NAND (Y NAND Y); and an XOR is built from four NANDs. The complete full subtractor uses roughly 14 NAND gates.

Final AnswerD = A ⊕ B ⊕ Bin; Bout = A′B + A′Bin + B·Bin — realised with about 14 two-input NAND gates by substituting each AND, OR, NOT and XOR.
Q4

A 1-to-2 line decoder

Write a PLC program that implements a 1-to-2 decoder.

ShowHide worked solution

A 1-to-2 decoder has one address input A and two outputs; exactly one output is high at a time. Y₀ = A′ and Y₁ = A.

Ladder program
|---[/A]----------------( Y0 )---|
|---[ A]----------------( Y1 )---|

Two rungs — Y0 driven by the NC contact of A, Y1 by the NO contact.

Final AnswerTwo rungs: Y₀ = A′ (NC contact), Y₁ = A (NO contact).
Q5

A 3-to-8 line decoder in ladder logic

Using the Ladder Diagram language, implement a 3-to-8 line decoder inside a PLC.

ShowHide worked solution

Three address inputs A, B, C drive eight outputs Y₀…Y₇. Output Yn is high only when the binary value of ABC equals n, so each output is one unique product term.

Y0 = A′B′C′ Y1 = A′B′C Y2 = A′BC′ Y3 = A′BC Y4 = AB′C′ Y5 = AB′C Y6 = ABC′ Y7 = ABC
Ladder program
|---[/A]---[/B]---[/C]----( Y0 )---|
|---[/A]---[/B]---[ C]----( Y1 )---|
|---[/A]---[ B]---[/C]----( Y2 )---|
|---[/A]---[ B]---[ C]----( Y3 )---|
|---[ A]---[/B]---[/C]----( Y4 )---|
|---[ A]---[/B]---[ C]----( Y5 )---|
|---[ A]---[ B]---[/C]----( Y6 )---|
|---[ A]---[ B]---[ C]----( Y7 )---|

Eight rungs — each uses three series contacts (NO/NC chosen by the binary index).

Final AnswerEight rungs, one per output; each rung is a 3-contact AND of A, B, C in the NO/NC pattern of that output’s binary index.
Q6

A 4-bit binary-to-BCD converter

Build a 4-bit binary-to-BCD converter as a ladder program. Whenever the BCD output would fall outside the valid range, do not rely on don’t-care states — instead, begin processing the next incoming number.

ShowHide worked solution

A 4-bit binary value ranges 0–15, but one BCD digit only covers 0–9. For values 10–15 a two-digit BCD result is needed, produced with the “add-3” (double-dabble) method.

Let the binary inputs be I3 I2 I1 I0, and let X flag a value of 10 or more:

X = I3 · (I2 + I1) If X = 0 : BCD tens = 0000 , BCD units = I3 I2 I1 I0 If X = 1 : BCD units = (I3 I2 I1 I0) + 0110 , BCD tens = 0001

In ladder, X is detected on one rung; an ADD instruction adds 0110 to the lower nibble when X is true and the tens digit is set to 1. If a result ever falls outside 0–9, the program does not use don’t-cares — it simply moves on to process the next incoming number.

Final AnswerDetect “≥ 10” with X = I3·(I2 + I1); if X = 1 add 0110 to the lower nibble and set the tens digit to 1, otherwise pass the value through unchanged. Use the PLC’s ADD instruction for the addition.
Q7

Displaying the square of a 2-bit number on a seven-segment display

Design a simplified circuit that displays, on a seven-segment indicator, the square of a two-bit binary input.

ShowHide worked solution

The two-bit input N takes values 0, 1, 2, 3, whose squares are 0, 1, 4, 9 — all single digits, so one seven-segment display suffices.

Segment pattern for each square (1 = segment ON).
N₁N₀abcdefg
0001111110
0110110000
1040110011
1191111011

Simplifying each segment column gives:

a = (N₀ ⊙ N₁) b = 1 c = 1 d = (N₀ ⊙ N₁) e = N₁′·N₀′ f = N₁ + N₀′ g = N₁
Final AnswerSegments b and c are tied permanently ON; a and d are driven by the XNOR of N₀ and N₁; e = N₁′N₀′, f = N₁ + N₀′, and g = N₁.
Q8

An SR flip-flop with both Q and Q′ outputs

Implement an SR (Set-Reset) flip-flop in a PLC using the Ladder Logic language. Make both outputs Q and Q′ available, and ensure that every output is generated correctly.

ShowHide worked solution
SR flip-flop behaviour — the 1,1 input is forbidden.
SRQ (next)
00Q (hold)
010
101
11forbidden

In the set-dominant version, Q seals itself on through its own contact and is broken only by R; pressing S forces Q high. A second rung simply mirrors the inverse of Q to a separate coil so the complement Q′ is also available.

Ladder program
|---[ S ]---+----[/R]----+-------( Q  )--|
|           |            |
|---[ Q ]---+            |
|
|---[/Q]------------------------( Q' )--|

One latching rung for Q (S sets, R resets, Q seals); one auxiliary rung for Q′.

Final AnswerA latching rung — S sets, R resets, Q seals through its own contact — plus an auxiliary rung [/Q] → (Q′) gives the complement.
Q9

A bistable multivibrator — toggle on every pulse

Write a PLC program that behaves as a simple bistable multivibrator. On every successive trigger pulse the output should toggle between its two stable states.

ShowHide worked solution

This is a T (toggle) flip-flop — each rising edge of the trigger flips the output. A one-shot rising (OSR) instruction turns each press into a single-scan pulse, which is routed to SET if Q is currently OFF, or to RESET if Q is currently ON.

Ladder program
|---[OSR T]---[/Q]----------------( SET )--|
|---[OSR T]---[ Q]----------------( RST )--|
|---[ SET ]---+----[/RST]---------( Q   )--|
|             |                   |
|---[ Q  ]----+-------------------+

Each press issues a one-scan pulse; Q seals through its own contact and the SET/RST flags flip it.

Final AnswerUse a one-shot on the trigger; route the pulse to SET when Q = 0 or to RESET when Q = 1. Output Q seals through its own contact, toggling on every pulse.
Q10

Converting a NOR/NOT circuit to basic gates

Take a given logic circuit built only from NOR and NOT gates and convert it into an equivalent circuit using only the basic gates (AND, OR and NOT).

ShowHide worked solution

De Morgan’s law gives the key substitution: NOR(X,Y) = (X + Y)′ = X′·Y′. Replace each NOR by an AND of inverted inputs, and keep each NOT as-is.

As a worked example, take a two-stage NOR chain F = NOR(NOR(A,B), C):

NOR(A, B) = A′·B′ F = NOR(A′B′, C) = (A′B′)′ · C′ = (A + B) · C′

The equivalent basic-gate circuit is therefore an OR gate on A and B, an inverter on C, and an AND gate combining the two.

Final AnswerReplace each NOR(X,Y) with X′·Y′ (equivalently (X+Y)′) and simplify with De Morgan. The example reduces to F = (A + B)·C′.
Q11

Converting a circuit to a single universal gate

For a given logic circuit, produce a simplified universal-gate equivalent — either NAND-only or NOR-only.

ShowHide worked solution

Each basic function has a fixed universal-gate substitution:

Universal-gate substitutions for NOT, AND and OR.
FunctionNAND-onlyNOR-only
NOT XX NAND XX NOR X
X·Y(X NAND Y) NAND (X NAND Y)(X NOR X) NOR (Y NOR Y)
X+Y(X NAND X) NAND (Y NAND Y)(X NOR Y) NOR (X NOR Y)

For example, F = A·B + C in NAND-only form: form AB with two NANDs, invert C with one NAND, then combine — about four NAND gates in total, functionally identical to the original.

Final AnswerReplace every AND, OR and NOT in the source circuit by the matching NAND-only (or NOR-only) equivalent from the table — the result uses a single gate type and behaves identically.
Q12

A 4-bit adjacent-1s detector (POS-form ladder)

From the supplied truth table, design a simplified POS-form ladder program for a 4-bit adjacent-1s detector. Output F is asserted whenever the 4-bit input ABCD contains two or more adjacent 1s.

ShowHide worked solution

From the truth table, F = 1 at minterms 3, 6, 7, 11, 12, 13, 14, 15. Plotting these gives the map below.

K-map of the adjacent-1s detector — rows AB, columns CD.
AB \ CD00011110
000010
010011
111111
100010

Grouping gives a compact sum-of-products — each term is simply a pair of adjacent bits both being 1:

FSOP = AB + BC + CD FPOS = (A + C)(B + C + D)(A + B + D)
Ladder program
|---[ A ]---[ B ]---+----( F )--|
|                   |
|---[ B ]---[ C ]---+
|                   |
|---[ C ]---[ D ]---+

Three parallel branches — AB, BC, CD — feed one output coil.

Final AnswerF = AB + BC + CD (any two adjacent bits both 1); equivalently F = (A+C)(B+C+D)(A+B+D). The ladder is three parallel branches feeding a single coil.
Q13

Truth table for the three-variable XOR

Construct the truth table for the three-variable XOR function.

ShowHide worked solution

The three-variable XOR is the odd-parity function: F = A ⊕ B ⊕ C is 1 whenever an odd number of inputs are 1.

Three-variable XOR — odd-parity output.
ABCF = A⊕B⊕C
0000
0011
0101
0110
1001
1010
1100
1111

Its sum-of-products expansion is F = A′B′C + A′BC′ + AB′C′ + ABC — the four rows where the count of 1s is odd.

Final AnswerF(A,B,C) = A ⊕ B ⊕ C = 1 whenever the number of 1s among A, B, C is odd.