PLC Book Part I — Foundations Chapter 4
Chapter 4 Part I · Foundations of PLC Systems Beginner ⏱ 35 min read ✦ 7 PLC Programs

04

Fundamentals of Logic

This is the chapter that turns you from someone who knows what a PLC is into someone who can actually start thinking like one. We’ll learn how a PLC makes decisions — using the same simple “yes/no” rules that you already use every day without realising it. Then we’ll build seven complete ladder logic programs — one for each gate — so you finish this chapter able to read and write your first PLC code.

What you’ll be able to do after this chapter

Your goals for this chapter:

  • Explain the binary concept and give three examples of “two-state” things from everyday life.
  • Recognise the AND, OR, NOT, and Exclusive-OR (XOR) gate symbols and complete their truth tables from memory.
  • Write a Boolean expression for a logic problem — and read one back out as plain English.
  • Draw a logic gate circuit from a Boolean expression, and write the Boolean expression for a circuit.
  • Explain the difference between hardwired logic and programmed logic, and say why most factories prefer the second one.
  • Use word-level logic instructions to operate on a whole 16-bit word at once.
  • Read and build complete ladder programs for all seven logic gates: AND, OR, NOT, NAND, NOR, XOR, and XNOR.

Key Concepts & Terms

Binary conceptLogic gateTruth table ANDORNOT (Inverter)NANDNORXORXNOR Boolean algebraBoolean expression Commutative lawAssociative lawDistributive law De Morgan’s theorems Hardwired logicProgrammed logic Ladder rungXIC · XIO · OTE Word-level logic
Section 4.1

The Binary Concept — Yes or No, Nothing in Between

Let me start with something you already know. When you flip a light switch, the light is either on or off. There is no “kind of on”. When you press a doorbell, it is either pressed or not pressed. When a door is closed, it is either closed or open.

This is the binary concept: the idea that a lot of things in the world have only two states, and we can call those states 1 and 0. The 1 might mean ON, the 0 might mean OFF — but the same two digits can represent any pair of opposites:

  • 1 = ON, 0 = OFF
  • 1 = OPEN, 0 = CLOSED (or the other way round — depends on the device)
  • 1 = TRUE, 0 = FALSE
  • 1 = HIGH voltage (like +24 V), 0 = LOW voltage (0 V)
  • 1 = “I see something”, 0 = “I see nothing” (a sensor)

Why is this useful? Because there is no middle ground. A computer or PLC never has to ask “is this signal 47 % on?” — the answer is always a clean yes or no. That is the secret behind how digital systems can be so fast and so reliable.

Real-world example

Think about the high-beam lights on a car. They turn on only when two things are true at the same time: the headlight switch is on, AND the high-beam switch is pulled. If either one is off, no high beams. This is your first logic decision — and you’ve been making it for years without thinking about it. The PLC just does the same thing, very fast, for many switches at once.

A logic gate is a tiny electronic circuit that takes one or more binary inputs and produces a single binary output, based on a fixed rule. The rule decides what combinations of inputs will turn the output ON. The rest of this chapter is about understanding those rules — because they are the same rules a PLC uses to decide whether a motor should run, a valve should open, or an alarm should sound.

Section 4.2

The Four Basic Gates — AND, OR, NOT, and XOR

Every digital system in the world — every PLC, every smartphone, every laptop — is built from just a handful of basic logic gates. Let’s meet the four most important ones. Each gate has:

  • A name describing what it does (“AND”, “OR” and so on).
  • A standard symbol used in circuit diagrams.
  • A truth table — a small table that shows the output for every possible combination of inputs.
  • A Boolean expression — a tiny mathematical formula that describes the gate.
THE FOUR BASIC LOGIC GATES Symbol · Truth table · Real-life situation AND Output is 1 only when ALL inputs are 1 A B Y Y = A · B A B Y 000 010 100 111 🚗 Car high-beams Headlights ON AND high-beam ON OR Output is 1 if ANY input is 1 A B Y Y = A + B A B Y 000 011 101 111 🚪 Car dome light Driver door OR passenger door open NOT Inverts the input — flips 0 to 1, 1 to 0 A Y Y = A̅ A Y 01 10 🚗 “Door OPEN” warning NOT closed → light is on XOR Output is 1 only when inputs are DIFFERENT A B Y Y = A ⊕ B A B Y 000 011 101 110 💡 Two-way stair light Switches in different positions

Figure 4.1 — The Four Basic Logic GatesEach gate has its own symbol, truth table, and a real-life situation that behaves the same way. Memorise these — every PLC program you ever write is built from them.

The AND Gate — “Both Conditions Must Be True”

An AND gate looks at all its inputs and outputs a 1 only when every single input is a 1. If even one input is 0, the output is 0. The Boolean shorthand is Y = A · B (the dot is “AND”) or simply Y = AB.

Where you’d use it: a machine should only start when the safety guard is closed AND the start button is pressed. A mixer should only run when the temperature is high enough AND the lid is closed. The word “and” in plain English almost always becomes an AND gate in the PLC program.

The OR Gate — “Any Condition Will Do”

An OR gate outputs a 1 if at least one of its inputs is a 1. The output is 0 only when every input is 0. Boolean shorthand: Y = A + B (the plus sign is “OR” in Boolean — don’t confuse it with addition).

Where you’d use it: an alarm should sound when the door OR the window is open. A pump should run when tank A is full OR tank B is full. Whenever you hear “either … or …”, you’re hearing an OR gate.

The NOT Gate — “Flip the Answer”

The NOT gate is the simplest of all — it has only one input. If the input is 1, the output is 0. If the input is 0, the output is 1. It just flips whatever you give it. Boolean shorthand: Y = A̅ (a bar over the letter means “NOT this”).

Where you’d use it: a “DOOR OPEN” warning light should turn on when the door is NOT closed. The NOT gate is also called an inverter because it inverts (flips) the signal.

The Exclusive-OR (XOR) — “One but Not Both”

The XOR gate is the picky cousin of the OR gate. Its output is 1 only when its inputs are different from each other (one is 1 and the other is 0). If both inputs are the same — both 0 or both 1 — the output is 0. Boolean: Y = A ⊕ B.

Where you’d use it: the classic example is a stair light with a switch at the top and bottom. The light turns on when one switch is up and the other is down — and turns off when both are up or both are down. XOR is also the heart of binary addition (since 1 + 1 = 10 — the result bit is 0, not 2).

NAND, NOR, and XNOR — The “Inverted” Versions

Three more gates worth knowing — each one is just an “inverted” version of one of the four above:

  • NAND = “AND followed by NOT” — gives the opposite of AND. Drawn as the AND symbol with a small bubble at the output.
  • NOR = “OR followed by NOT” — opposite of OR. Drawn as the OR symbol with a bubble.
  • XNOR = “XOR followed by NOT” — output is 1 when inputs are the same (the opposite of XOR).

NAND and NOR are special: any logic circuit can be built using only NAND gates, or only NOR gates. They are called universal gates for that reason.

Section 4.3

Boolean Algebra — A Tiny New Math Just for Logic

You already know regular algebra: 2 + 3 = 5, x · y = y · x, and so on. Boolean algebra is exactly the same idea, but instead of numbers we use the binary values 0 and 1, and instead of plus, minus, and times we use AND, OR, and NOT.

Why bother? Because Boolean algebra lets us write down a complicated logic problem as a short formula, then simplify it into a smaller circuit. A simpler circuit means fewer gates, fewer lines of code, fewer chances for bugs, and a faster scan time.

The Boolean Symbols

SymbolMeaningExampleRead as
·ANDA · B“A AND B”
+ORA + B“A OR B”
A̅ (bar)NOT“NOT A”
Exclusive-OR (XOR)A ⊕ B“A XOR B”
=“results in”Y = AB“Y is A AND B”

Notice that the AND dot is often left out — AB means the same as A · B, just like in regular algebra xy means x · y. The plus sign is OR in Boolean — don’t accidentally read it as ordinary addition.

Three Laws You Need to Know

Most Boolean laws look exactly like the laws of ordinary algebra. There is one important exception — the second part of the distributive law, which only works in Boolean algebra.

The Three Basic Laws

Same as ordinary algebra:

Commutative law: A + B = B + A A · B = B · A (Order does not matter.) Associative law: (A + B) + C = A + (B + C) (A · B) · C = A · (B · C) (Grouping does not matter.) Distributive law: A · (B + C) = (A · B) + (A · C) This one is Boolean-only: A + (B · C) = (A + B) · (A + C) (Yes — you really can “distribute” OR over AND. This does not work in ordinary algebra.)

De Morgan’s Theorems — Two Rules You Will Use Every Day

One more pair of laws is so important to PLC work that I want to call it out separately. Augustus De Morgan figured out two rules that link AND, OR, and NOT together:

De Morgan’s Theorems

The “bar splits, sign flips” rule:

Theorem 1: (A · B)̅ = A̅ + B̅ “NOT (A AND B)” equals “(NOT A) OR (NOT B)” Theorem 2: (A + B)̅ = A̅ · B̅ “NOT (A OR B)” equals “(NOT A) AND (NOT B)” In words: when you push a NOT inside parentheses, the bar splits across the variables AND the operator flips (AND ↔ OR).

Why does this matter? Because in ladder logic, AND becomes “contacts in series” and OR becomes “contacts in parallel”. De Morgan’s theorems let us convert a NAND into “NC contacts in parallel” and a NOR into “NC contacts in series” — which is exactly how we’ll build them in the worked programs at the end of this chapter.

Why Boolean algebra matters for PLC work

When you start writing ladder logic in Chapters 5 and 6, you’ll often find yourself with a long, messy rung that you suspect could be shorter. Boolean algebra — especially De Morgan’s theorems — gives you a structured way to simplify the logic on paper before you commit it to the program. A clean, simplified rung is easier to read, easier to troubleshoot, and faster to scan.

Section 4.4

Building a Logic Circuit from a Boolean Expression

Now let’s put it together. Suppose someone hands you a Boolean expression and asks you to draw the circuit. The trick is to read it from the inside out — handle the innermost operation first, then work outward.

Worked Example

Draw the circuit for Y = AB + C

Step 1 — Identify the operations from inside out: “AB” means A AND B. That result is then OR’d with C. Step 2 — Pick the gates you need: • One AND gate (inputs A and B → output AB) • One OR gate (inputs AB and C → output Y) Step 3 — Wire them together: A ──┐ │AND──┐ B ──┘ │OR ──── Y = AB + C │ C ────────┘ Done. Two gates, three inputs, one output.

Try a slightly bigger one. The expression Y = A(BC + D) needs three gates:

Worked Example

Draw the circuit for Y = A · (BC + D)

Step 1 — Innermost first: BC means B AND C. Step 2 — Then (BC + D) means BC OR D. Step 3 — Finally A · (whole thing) — A AND that. Gates needed: • AND gate 1 → B and C → output BC • OR gate → BC and D → output (BC + D) • AND gate 2 → A and (BC + D) → output Y B ──┐ │AND─── BC ──┐ C ──┘ │OR ── (BC+D) ──┐ │ │AND ── Y D ───────────────┘ │ │ A ───────────────────────────────┘

The pattern: read the Boolean expression from the inside out (deepest parentheses first), pick a gate for each operation, and chain the outputs together. With practice this becomes almost automatic.

Section 4.5

Going the Other Way — Reading a Circuit into a Boolean Expression

You also need to do the reverse: someone shows you a logic circuit and asks “what does this do?” To answer, you trace the circuit from the inputs forward to the output, writing down the result of each gate as you go.

Worked Example

A circuit has an OR gate (inputs A, B), a NOT gate on input D, and an AND gate that combines C, the OR output, and the inverted D. Find Y.

Step 1 — The OR gate outputs: A + B Step 2 — The NOT (inverter) outputs: D̅ Step 3 — The final AND gate combines C, (A+B), and D̅: Y = C · D̅ · (A + B) Read in plain English: “Y is true when C is on, AND D is OFF, AND (either A or B is on).”

The key skill here is patience: take it one gate at a time. Label each intermediate signal with its expression. By the time you reach the output, you’ve assembled the whole formula.

Section 4.6

Hardwired Logic vs. Programmed Logic — Why Factories Switched

This is the section that explains why PLCs took over the world.

Before PLCs existed, every logic decision in a factory was made by physical electrical equipment — relays, switches, timers, contactors — all wired together with copper. We call this hardwired logic. The “program” was the wiring itself. To change the logic, an electrician had to physically rewire the panel.

With a PLC, the same logic is stored in software inside the CPU. We call this programmed logic. To change the logic, you just edit the program on a laptop and download it. The wiring to the field devices does not change.

SAME PROBLEM, TWO WAYS “Run the motor when the START button is pressed AND the door is closed.” HARDWIRED LOGIC (relay panel) Physical relay coil + two switches in series. L1 START DOOR M L2 ⚠ To change the logic → physically rewire the panel. same logic PROGRAMMED LOGIC (PLC) One rung of ladder logic in the CPU’s memory. L1 START I:1/0 DOOR I:1/1 M O:2/0 L2 Y = START · DOOR ✓ To change the logic → edit the program, click “Download”.

Figure 4.2 — Hardwired Logic vs Programmed LogicThe same control problem solved two ways. The result is identical, but the PLC version can be modified in seconds with a laptop.

Why Programmed Logic Wins

  • Easy to change. A logic change in software takes minutes; the same change in a relay panel takes hours of rewiring.
  • Smaller and cheaper. One PLC the size of a textbook can replace a wall full of relays.
  • More reliable. No moving contacts to wear out, no coils to burn, no contacts to pit.
  • Self-documenting. The ladder logic on a screen shows exactly what the program is doing — much easier to follow than tracing wires through a panel.
  • Easier to troubleshoot. The engineer can watch the logic execute live on a laptop, with energised rungs lit up in green.

Hardwired logic isn’t completely dead, though. Some safety circuits — emergency stops, machine guarding interlocks — are still hardwired in parallel with the PLC, because regulators don’t trust software for life-and-limb decisions. But for everyday control, programmed logic has won the argument.

Section 4.7

Word-Level Logic Instructions — Operating on 16 Bits at Once

Up to now we’ve talked about logic working on single bits — one input, one output, one yes/no answer at a time. But PLCs can also do logic on entire words (groups of 16 or 32 bits) in a single instruction. These are called word-level logic instructions.

The four basic word-level instructions are:

  • AND (mask) — perform a bit-by-bit AND between two 16-bit words. Used to “mask” off bits you don’t care about — set them to 0.
  • OR — bit-by-bit OR between two words. Used to set certain bits without disturbing the others.
  • NOT — invert every bit in a word.
  • XOR — bit-by-bit XOR between two words. Used to detect which bits have changed between two readings.

How does it actually work? The PLC takes the two 16-bit words, lines them up bit by bit, and applies the gate’s rule to every bit position independently. The result is a new 16-bit word.

Worked Example — Word-Level AND

AND together two 16-bit words to mask off the low byte

Word A: 1011 0110 1100 1010 Word B: 1111 1111 0000 0000 ← the “mask” AND Result: 1011 0110 0000 0000 Bit by bit, the rule “1 AND x = x” passes the high byte through unchanged, and “0 AND x = 0” forces the low byte to zero. Use case: you have a 16-bit input word but only care about the upper 8 bits. AND with this mask isolates them in one instruction.

Why this matters in real PLC work

Suppose you have an analog reading stored in a 16-bit word, but only the lower 12 bits hold the actual value (the top 4 bits hold status flags from the I/O module). To get the clean reading, AND the word with the mask 0000 1111 1111 1111. One instruction, done. Without word-level logic, you’d need 12 separate bit-by-bit operations.

Worked PLC Programs

Seven Ladder Programs — One for Each Logic Gate

Now let’s turn the theory into actual PLC code. We’ll build a complete ladder logic program for each of the seven gates: AND, OR, NOT, NAND, NOR, XOR, and XNOR. Same two switches, same one lamp, seven different control rules. By the end, you’ll be able to read any ladder rung at a glance.

LADDER LOGIC — THREE INSTRUCTIONS YOU NEED FIRST Every ladder rung uses these three building blocks. Learn them, then read the seven programs below. XIC Examine If Closed Passes power if input bit is ON (1) drawn like a normally-open contact XIO Examine If Open Passes power if input bit is OFF (0) drawn like a normally-closed contact OTE Output Energize Sets output bit to 1 when rung is true drawn like an output coil

Figure 4.3 — The Three Ladder Instructions You’ll Use TodayXIC tests for a 1, XIO tests for a 0, and OTE drives an output. Combine these three with series (AND) and parallel (OR) wiring and you can build any logic gate.

Two more conventions before we start: contacts in series (one after another on the same rung) act like an AND — both must pass power for the rung to be true. Contacts in parallel (stacked branches) act like an OR — any one passing power makes the rung true. That’s it. With XIC, XIO, OTE, series, and parallel, you can build every gate.

01

PLC Program · AND-family

Implementing an AND Gate in Ladder Logic

AND

The problem: a lamp must turn on only when both switches X1 and X2 are pressed at the same time. If either switch is released, the lamp must turn off. Write a one-rung PLC program for this.

Inputs & Outputs

INPUTS

X1 — push-button switch 1

X2 — push-button switch 2

OUTPUT

Y1 — lamp (or motor)

Truth Table

X1X2Y1Lamp state
000OFF
010OFF
100OFF
111ON

Ladder Diagram

L1 L2 000 X1 XIC X2 XIC Y1 OTE

Two XIC contacts in series drive Y1 — series wiring is the AND function.

How it works

Power flows from L1 along the rung. The first XIC (X1) lets power through only if X1 is ON. That power then meets the second XIC (X2), which only lets it through if X2 is also ON. So Y1 energizes only when both X1 AND X2 are ON. Boolean: Y1 = X1 · X2.

What we learned: contacts placed one after another on the same rung — in series — implement an AND gate. The rung is true only when every contact in the series passes power.
02

PLC Program · OR-family

Implementing an OR Gate in Ladder Logic

OR

The problem: an alarm Y1 must sound when either the door switch X1 is open, or the window switch X2 is open (or both). Y1 stays off only when both inputs are off.

Inputs & Outputs

INPUTS

X1 — door switch (1 = open)

X2 — window switch (1 = open)

OUTPUT

Y1 — alarm buzzer

Truth Table

X1X2Y1Alarm state
000silent
011ON
101ON
111ON

Ladder Diagram

L1 L2 000 XIC X1 XIC X2 Y1 OTE

Two XIC contacts in parallel drive Y1 — parallel wiring is the OR function.

How it works

The rung now has two paths from L1 to the output coil. The top branch passes power if X1 is ON. The bottom branch passes power if X2 is ON. Either branch is enough to energize Y1, so the alarm sounds when X1 OR X2 (or both) are ON. Boolean: Y1 = X1 + X2.

What we learned: contacts arranged as parallel branches — in parallel — implement an OR gate. The rung is true if any branch passes power.
03

PLC Program · NOT

Implementing a NOT (Inverter) in Ladder Logic

NOT

The problem: a “DOOR OPEN” warning lamp Y1 must turn on whenever the door switch X1 is not closed. When the door is closed (X1 = 1), the lamp goes off.

Inputs & Outputs

INPUT

X1 — door-closed sensor (1 = closed, 0 = open)

OUTPUT

Y1 — “DOOR OPEN” warning lamp

Truth Table

X1Y1Lamp state
01ON (door open → warn)
10OFF (door closed → safe)

Ladder Diagram

L1 L2 000 X1 XIO Y1 OTE

A single XIO contact drives Y1 — XIO is “true when input is OFF”, which is exactly the NOT function.

How it works

The XIO instruction is the inverse of XIC — it passes power when the input bit is OFF (0). So when the door is open (X1 = 0), the XIO is true, the rung passes, and the warning lamp Y1 lights up. When the door is closed (X1 = 1), the XIO blocks power and the lamp turns off. Boolean: Y1 = X̅1.

What we learned: the XIO instruction is the NOT gate of ladder logic. A single XIO contact gives you an inverter without any extra wiring.
04

PLC Program · AND-family

Implementing a NAND Gate in Ladder Logic

NAND

The problem: a cooling fan Y1 must turn on whenever either temperature sensor X1 or X2 reports “below threshold” (0). The fan turns off only when both sensors confirm “above threshold” (both 1). This is the NAND of X1 and X2.

By De Morgan’s first theorem: (X1 · X2)̅ = X̅1 + X̅2. So NAND becomes “NOT-X1 OR NOT-X2” — two XIO contacts in parallel.

Inputs & Outputs

INPUTS

X1 — temperature sensor 1 (1 = high)

X2 — temperature sensor 2 (1 = high)

OUTPUT

Y1 — cooling fan

Truth Table

X1X2Y1Fan state
001ON
011ON
101ON
110OFF

Ladder Diagram

L1 L2 000 XIO X1 XIO X2 Y1 OTE

Two XIO contacts in parallel — by De Morgan, this is X̅1 + X̅2 = (X1·X2)̅ = NAND.

How it works

Each XIO is true when its input is OFF. As long as at least one input is OFF, one of the parallel branches is true and Y1 energizes. Only when both X1 and X2 are ON do both XIO contacts block, the rung becomes false, and Y1 turns off — exactly the NAND truth table. Boolean: Y1 = X̅1 + X̅2 = (X1·X2)̅.

What we learned: NAND in ladder logic = two XIO contacts in parallel. De Morgan converts the inverted-AND into a “NOT-A OR NOT-B” form that maps cleanly onto two parallel branches.
05

PLC Program · OR-family

Implementing a NOR Gate in Ladder Logic

NOR

The problem: a “READY” lamp Y1 must light only when both safety guards X1 and X2 are closed (both 0 — a fault sensor reads 1 when a guard is open). If either guard is open, the lamp must go dark. This is the NOR of X1 and X2.

By De Morgan’s second theorem: (X1 + X2)̅ = X̅1 · X̅2. So NOR becomes “NOT-X1 AND NOT-X2” — two XIO contacts in series.

Inputs & Outputs

INPUTS

X1 — guard 1 fault (1 = open)

X2 — guard 2 fault (1 = open)

OUTPUT

Y1 — “READY” lamp

Truth Table

X1X2Y1Lamp state
001ON (ready)
010OFF
100OFF
110OFF

Ladder Diagram

L1 L2 000 X1 XIO X2 XIO Y1 OTE

Two XIO contacts in series — by De Morgan, this is X̅1 · X̅2 = (X1+X2)̅ = NOR.

How it works

Each XIO blocks power if its input is ON. With two XIO in series, power makes it through the entire rung only when both inputs are OFF. The moment either guard opens (input goes to 1), its XIO blocks and the lamp goes off — exactly the NOR truth table. Boolean: Y1 = X̅1 · X̅2 = (X1+X2)̅.

What we learned: NOR in ladder logic = two XIO contacts in series. Notice the symmetry: NAND uses XIO in parallel, NOR uses XIO in series. De Morgan’s theorems are doing all the work for us.
06

PLC Program · XOR-family

Implementing an XOR Gate in Ladder Logic

XOR

The problem: the classic two-way stair light. Switch X1 is at the bottom of the stairs, switch X2 is at the top. Either switch should turn the lamp Y1 on or off. The lamp is on when the switches are in different positions, off when they match.

XOR isn’t a single contact pattern — we have to expand it: X1 ⊕ X2 = (X1 · X̅2) + (X̅1 · X2). That’s two parallel branches, each containing one XIC and one XIO in series.

Inputs & Outputs

INPUTS

X1 — bottom switch

X2 — top switch

OUTPUT

Y1 — stair lamp

Truth Table

X1X2Y1Lamp state
000OFF (both down)
011ON
101ON
110OFF (both up)

Ladder Diagram

L1 L2 000 XIC X1 XIO X2 XIO X1 XIC X2 Y1 OTE

Two parallel branches, each a 1-true-1-false combination — implements (X1·X̅2) + (X̅1·X2) = XOR.

How it works

The top branch passes power when X1 is ON and X2 is OFF. The bottom branch passes power when X1 is OFF and X2 is ON. Either branch alone energizes Y1, but if both inputs are the same (both ON or both OFF), neither branch passes power and Y1 stays off. Result: lamp is on only when the switches are different — exactly XOR.

What we learned: XOR needs two parallel branches, each combining XIC and XIO. Pattern to remember: (A·B̅) + (A̅·B) — “first input on AND second off, OR first off AND second on.”
07

PLC Program · XOR-family

Implementing an XNOR Gate in Ladder Logic

XNOR

The problem: a “MATCH OK” indicator Y1 must light when the two operator switches X1 and X2 are in the same position (both up or both down). When they disagree, the indicator goes off. This is XNOR — the opposite of XOR.

The Boolean form: X1 ⊙ X2 = (X1 · X2) + (X̅1 · X̅2) — two parallel branches, one with both XIC, one with both XIO.

Inputs & Outputs

INPUTS

X1 — operator switch 1

X2 — operator switch 2

OUTPUT

Y1 — “MATCH OK” indicator

Truth Table

X1X2Y1Indicator
001ON (both down — match)
010OFF
100OFF
111ON (both up — match)

Ladder Diagram

L1 L2 000 XIC X1 XIC X2 XIO X1 XIO X2 Y1 OTE

Top branch fires when both inputs are ON; bottom branch fires when both are OFF — XNOR.

How it works

The top branch (XIC X1 in series with XIC X2) is true only when both X1 AND X2 are ON. The bottom branch (XIO X1 in series with XIO X2) is true only when both X1 AND X2 are OFF. The two branches cover both “match” cases. Whenever the inputs disagree, neither branch passes power and Y1 stays off. Result: Y1 = (X1·X2) + (X̅1·X̅2).

What we learned: XNOR is XOR’s mirror image. Replace XIC with XIO (and vice-versa) in each branch of the XOR program, and you have XNOR. Both gates use the same parallel-of-series structure — only the contact types swap.

Common Student Mistakes

Things to watch out for in this chapter:

  • Reading + as ordinary addition. In Boolean algebra, + means OR, not “plus”. So 1 + 1 = 1 in Boolean (not 2). Always remember which kind of math you’re doing.
  • Confusing OR with XOR. Plain OR is true if any input is true (including both). XOR is true only when inputs are different. Both 1s give 1 for OR, but 0 for XOR.
  • Forgetting the bar means NOT. When you see , read it as “NOT A”. A bar over a longer expression like (A + B)̅ means “NOT (A OR B)” — different from A̅ + B̅.
  • Mixing up AND-then-NOT with NOT-then-AND. A̅ · B̅ is “NOT-A AND NOT-B” — totally different from (A · B)̅ which is “NOT (A AND B)”. The bar’s position changes everything.
  • Confusing XIC with NO contact in the field. XIC is the instruction “examine if closed (1)”. The actual field switch may be normally-open or normally-closed — that’s a wiring decision, not a software one. The XIC just asks “is the bit a 1?”
  • Drawing parallel branches wrong. Parallel branches must connect to the rung at both ends — left and right. Forgetting the right-side junction is the classic beginner error and creates a non-functional rung.
  • Treating hardwired safety circuits as optional. Some logic — like an emergency stop — must be hardwired by law, not just programmed. Don’t assume that because the PLC can do everything, it should.

Quick Recap

The eight things to take away from Chapter 4:

  • The binary concept: every signal in a PLC is either 1 or 0 — there is no in-between.
  • The four basic gates are AND (all inputs 1), OR (any input 1), NOT (flip the input), and XOR (inputs different).
  • Boolean algebra uses · for AND, + for OR, and a bar for NOT — the same algebra you know, applied to 1s and 0s.
  • De Morgan’s theorems: (AB)̅ = A̅+B̅ and (A+B)̅ = A̅·B̅ — the bar splits, the operator flips.
  • Hardwired logic uses physical relays and wiring; programmed logic stores the same decisions in PLC memory. Programmed logic wins on flexibility, size, reliability, and troubleshooting.
  • Word-level logic instructions apply AND, OR, NOT, or XOR to all 16 bits of a word at once — perfect for masking, setting, or detecting changes.
  • In ladder logic, XIC tests for 1, XIO tests for 0, OTE drives an output. Series contacts = AND, parallel branches = OR.
  • All seven gates can be built from XIC, XIO, and OTE alone: AND = XIC series, OR = XIC parallel, NOT = single XIO, NAND = XIO parallel, NOR = XIO series, XOR and XNOR = parallel of series.

Review & Self-Assessment

Chapter 4 Review Questions

Try answering each question on your own first. Tap to reveal the answer when you’re done.

Q1Explain the binary concept in your own words and give two examples from everyday life.+
The binary concept is the idea that many things have only two possible states — on/off, true/false, open/closed — with nothing in between. Examples: a light switch (on or off), a door (open or closed), a doorbell (pressed or not pressed), a sensor (detecting something or not). The PLC uses this concept because it lets every decision be a clean yes-or-no answer.
Q2Complete the truth table for a 2-input AND gate.+
A=0, B=0 → Y=0.   A=0, B=1 → Y=0.   A=1, B=0 → Y=0.   A=1, B=1 → Y=1. The output is 1 only when both inputs are 1.
Q3What is the difference between an OR gate and an XOR gate?+
An OR gate’s output is 1 whenever any input is 1, including when both inputs are 1. An XOR gate’s output is 1 only when the inputs are different (one is 1 and the other is 0). When both inputs are 1, OR gives 1 but XOR gives 0.
Q4Write the Boolean expression for: “Output Y is 1 when A AND B are both 1, OR when C is 1.”+
Y = AB + C   (or Y = A·B + C). The “AND” between A and B is the dot (or no symbol at all), and “OR” between AB and C is the plus sign.
Q5State De Morgan’s two theorems and explain why they matter for ladder logic.+
Theorem 1: (A·B)̅ = A̅ + B̅. Theorem 2: (A+B)̅ = A̅ · B̅. They matter because in ladder logic, AND becomes “contacts in series” and OR becomes “contacts in parallel”. De Morgan lets us turn a NAND (which has no direct ladder symbol) into “two XIO contacts in parallel”, and a NOR into “two XIO contacts in series”.
Q6Give three reasons why programmed logic has replaced hardwired logic in most factories.+
Any three of: (1) easier to change — software edit instead of physical rewiring; (2) smaller and cheaper — one PLC replaces a wall of relays; (3) more reliable — solid-state, no moving contacts; (4) easier to troubleshoot — watch the logic run live on a laptop; (5) self-documenting — ladder rungs are easier to read than tracing wires.
Q7When would you still use hardwired logic instead of (or in addition to) programmed logic?+
For safety-critical circuits — emergency stops, machine guarding interlocks, fire shutdowns. Regulators in most countries do not trust software alone for life-safety functions, so these circuits are hardwired in parallel with the PLC.
Q8If word A = 1100 1010 and word B = 1010 0101, what is A XOR B (bit by bit)?+
XOR each pair of bits: 1⊕1=0, 1⊕0=1, 0⊕1=1, 0⊕0=0, 1⊕0=1, 0⊕1=1, 1⊕0=1, 0⊕1=1. Result: 0110 1111. (XOR shows you which bit positions are different between the two words.)
Q9What does XIC stand for, and when does it pass power to the rest of the rung?+
XIC = Examine If Closed. It passes power when the input bit it references is ON (1). It’s drawn as a normally-open contact (two short vertical bars). Despite the name “Closed”, it has nothing to do with the physical state of a switch in the field — it’s purely a software test on a memory bit.
Q10In ladder logic, what does it mean to wire contacts in series vs in parallel?+
Series = contacts placed one after another on the same horizontal line. The rung is true only if every contact passes power. Series implements an AND. Parallel = contacts on separate branches that join back together. The rung is true if any branch passes power. Parallel implements an OR.
Q11Sketch a ladder rung that implements the NAND function on inputs X1 and X2 with output Y1.+
By De Morgan: (X1·X2)̅ = X̅1 + X̅2. So draw two XIO contacts in parallel driving an OTE Y1: top branch has XIO X1, bottom branch has XIO X2, both branches join into the OTE. The output is 1 whenever at least one input is 0 — the NAND truth table.
Q12An XOR rung uses two parallel branches. What contacts go in each branch, and why?+
XOR = (X1·X̅2) + (X̅1·X2). Top branch: XIC X1 in series with XIO X2 — true when X1 is on AND X2 is off. Bottom branch: XIO X1 in series with XIC X2 — true when X1 is off AND X2 is on. The OR (parallel) of these two means the rung is true exactly when the inputs are different — which is XOR.

Need help with logic gates, ladder rungs, or your first PLC program?

Get one-on-one tutoring or project guidance from Dr Ahsan Rahman — Head of Electrical Engineering, with two decades of experience teaching digital logic and PLC programming.

Request Consultation →