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.
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′.
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₃.
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.
A
B
Bin
D
Bout
0
0
0
0
0
0
0
1
1
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
0
1
0
1
0
0
1
1
0
0
0
1
1
1
1
1
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.
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.
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₀
N²
a
b
c
d
e
f
g
0
0
0
1
1
1
1
1
1
0
0
1
1
0
1
1
0
0
0
0
1
0
4
0
1
1
0
0
1
1
1
1
9
1
1
1
1
0
1
1
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.
S
R
Q (next)
0
0
Q (hold)
0
1
0
1
0
1
1
1
forbidden
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.
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.
Function
NAND-only
NOR-only
NOT X
X NAND X
X 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 \ CD
00
01
11
10
00
0
0
1
0
01
0
0
1
1
11
1
1
1
1
10
0
0
1
0
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.
A
B
C
F = A⊕B⊕C
0
0
0
0
0
0
1
1
0
1
0
1
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
0
1
1
1
1
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.