← The review guideReference pages
Module 2 · Logic and number systems
First draft, for your review · about 3 hours
Recommended first
Nothing: this module can be the first. (recommended, not enforced)
What the learner will be able to do
- Convert whole numbers between decimal, binary and hexadecimal, and read a PLC word (an input module, an INT tag) as its bits. (plc.m2.o1)
- Read and write a number in BCD (binary-coded decimal), as thumbwheel switches and displays use it. (plc.m2.o2)
- Describe AND, OR and NOT, and the contacts that make each: in series, in parallel, and normally closed. (plc.m2.o3)
- Write the truth table of an expression with up to four inputs, using the order of operations, brackets and XOR, and turn a sentence into an expression. (plc.m2.o4)
Topics
Binary and hexadecimal · BCD · Boolean logic: AND, OR, NOT · Truth tables, XOR and the order of operations
About this module
A PLC only knows two things: on and off. Every input it reads, every output it drives and every number it keeps is stored as a row of bits, each one either 1 (on, TRUE) or 0 (off, FALSE).
This module gives you the two ideas that sit under every PLC program.
- Numbers as bits. A 16-point input module reports its inputs as one 16-bit number. A fault code on a drive's display is written in hexadecimal. A thumbwheel switch on an operator panel sends a number in BCD. To read these, you need to move between decimal, binary and hexadecimal, and to know what BCD is.
- Logic on TRUE and FALSE. "The press runs only if both hands are on the buttons AND the guard is closed" is a logic expression. AND, OR and NOT are exactly what contacts in series, contacts in parallel and a normally closed contact do in a ladder rung.
You will use the number systems again in module 7 (data and math), and the logic in every rung you write from module 5 on. Each item ends with practice questions on its Exercise tab, and the module check has the questions that count.
The items
Each item has four tabs in PLC+: Learn (the lesson below), Example (a machine running a working program), Exercise (the learner writes the program; PLC+ checks it) and Reference. Every item has a comment box under it.
- 2.1 Binary and hexadecimal
- 2.2 BCD: binary-coded decimal
- 2.3 AND, OR and NOT
- 2.4 Truth tables for larger expressions
- 2.5 Module check
2.1 Binary and hexadecimal
about 40 minutes
- Example
- None: this item has no machine.
- Exercise
- Practice questions (below). Passing them completes the item.
- Reference
- Number systems
The Learn tab
Binary and hexadecimal
Every number in a PLC is stored as a row of bits. A bit is one on/off value: 1 or 0. Counting with only the digits 0 and 1 is called binary (base 2).
Place values
In decimal, each place is worth ten times the place to its right: ones, tens, hundreds. In binary, each place is worth two times the place to its right. The places are numbered from 0, starting at the right.
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Worth | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
To read a binary number, add up the places that hold a 1. For example, 1011 0010 has 1s in bits 7, 5, 4 and 1: 128 + 32 + 16 + 2 = 178.
Binary numbers get long, so they are often written in groups of four bits, with a space or an underscore between groups. IEC 61131-3, the PLC programming standard, writes a binary number with 2# in front: 2#1011_0010. A textbook may write it as 10110010₂ instead.
Decimal to binary, step by step
Method 1: subtract place values. Write 37 in binary.
- The largest place value that fits in 37 is 32. Put a 1 in the 32 place. 37 − 32 = 5 is left.
- 16 does not fit in 5: 0. 8 does not fit: 0.
- 4 fits: 1. 5 − 4 = 1 is left.
- 2 does not fit: 0. 1 fits: 1. Nothing is left.
- Reading the places 32, 16, 8, 4, 2, 1: 100101. As eight bits:
2#0010_0101.
Method 2: divide by 2 again and again. Write down each remainder.
| Divide | Answer | Remainder |
|---|---|---|
| 37 ÷ 2 | 18 | 1 |
| 18 ÷ 2 | 9 | 0 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Read the remainders from the bottom up: 100101. Both methods agree. Check it: 32 + 4 + 1 = 37.
Hexadecimal: binary in short form
A group of four bits holds 0 to 15. Hexadecimal (hex, base 16) gives each of those sixteen values one digit: 0 to 9, then A to F for 10 to 15.
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Binary to hex: split the bits into groups of four from the right, and swap each group for its hex digit. 2#1011_0010 is 1011 = B and 0010 = 2, so it is 16#B2. Check: 11 × 16 + 2 = 178, the same as before.
Hex to binary: swap each hex digit for its four bits. 16#3C is 3 = 0011 and C = 1100, so it is 2#0011_1100. In decimal: 3 × 16 + 12 = 60.
IEC writes hex as 16#FF; you will also see 0xFF (in C and on many drives) and FFh. All three mean 255.
Where you meet this on a PLC
- An input module as a word. A 16-point input module reports its inputs as one 16-bit number: input 0 is bit 0, input 15 is bit 15. If inputs 0, 1 and 3 are on, the word is
2#0000_0000_0000_1011, which is 11, or16#000B. - Bits of a tag. On the lab's Allen-Bradley PLC you can read one bit of an integer tag by its number:
Status.3is bit 3 of the tag Status. - Status words and fault codes. A drive or module often reports a word of status bits in hex.
16#0041is2#0000_0000_0100_0001: bits 0 and 6 are on. The manual tells you what each bit means.
Sizes of data
| Type | Bits | Holds |
|---|---|---|
| BOOL | 1 | FALSE or TRUE |
| SINT | 8 | −128 to 127 |
| INT | 16 | −32,768 to 32,767 |
| DINT | 32 | about −2.1 billion to 2.1 billion |
INT and DINT use their top bit for the sign (plus or minus); module 7 explains how. Counted without a sign, 16 bits hold 0 to 65,535, which is 16#FFFF.
Try it
Open the Exercise tab for six practice questions: write numbers in binary and hex, read them back in decimal, and read an input module's word. Type a binary answer with only 0s and 1s (spaces are fine: 0010 1101). Type a hex answer with 0–9 and A–F; 16#, 0x and a trailing h are accepted. Each answer tells you why, and shows the right one when yours is wrong. Use the Reference tab for the 0–15 table.
The questions (on the Exercise tab)
6 questions; the learner needs 80 % to pass and can try again. Practice: a wrong answer shows the right one. The right answers are marked ✓ here only.
Type the answer. Write 45 in binary.
✓ 101101 (45 in binary; leading zeros, spaces and marks such as 16# or 0x are accepted)
Why: 45 = 32 + 8 + 4 + 1, so the 32, 8, 4 and 1 places hold 1s: 101101 (2#0010_1101 as eight bits).
A number. What is
2#1100_1010in decimal?✓ 202 (within 0)
Why: The 1s are in the 128, 64, 8 and 2 places: 128 + 64 + 8 + 2 = 202. In hex it is 16#CA: 12 × 16 + 10 = 202.
Type the answer. Write 200 in hexadecimal.
✓ C8 (200 in hexadecimal; leading zeros, spaces and marks such as 16# or 0x are accepted)
Why: 200 ÷ 16 = 12 remainder 8. 12 is C, so 200 is 16#C8. Check: 12 × 16 + 8 = 200.
A number. What is
16#3Fin decimal?✓ 63 (within 0)
Why: 3 × 16 + F (15) = 48 + 15 = 63. In binary it is 0011 1111.
Choose one. A 16-point input module's word reads
16#0005. Which inputs are on?- ✓ Inputs 0 and 2
- Input 5 only
- Inputs 0 and 1
- Inputs 1 and 3
Why: 16#0005 is 0000 0000 0000 0101 in binary. Counting from bit 0 on the right, bits 0 and 2 are 1, so inputs 0 and 2 are on.
Choose one. Counted from 0 and without a sign, what is the largest number 16 bits can hold?
- 255
- 32,768
- ✓ 65,535
- 99,999
Why: All sixteen bits on is 16#FFFF, which is 2 to the power 16, minus 1: 65,536 − 1 = 65,535. 255 is the largest for eight bits.
Your comments on this item
2.2 BCD: binary-coded decimal
about 30 minutes · builds on 2.1
- Example
- None: this item has no machine.
- Exercise
- Practice questions (below). Passing them completes the item.
- Reference
- BCD, Number systems
The Learn tab
BCD: binary-coded decimal
Some devices on a machine think in decimal digits, one digit at a time. A thumbwheel switch on an operator panel lets someone dial a number such as 308, one wheel per digit. A 7-segment display shows a count, one digit per window. These devices use BCD, short for binary-coded decimal.
The rule
BCD gives each decimal digit its own group of four bits. The group holds that digit in binary, 0 to 9.
| Digit | BCD bits |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
That is all of it. Ten digits, ten codes.
Decimal to BCD, step by step
Write 406 in BCD.
- Split the number into digits: 4, 0, 6.
- Write each digit as four bits: 4 = 0100, 0 = 0000, 6 = 0110.
- Put the groups side by side, in the same order: 0100 0000 0110.
Compare plain binary: 406 = 256 + 128 + 16 + 4 + 2 = 1 1001 0110. The two are different. BCD is not "the number in binary"; it is "each digit in binary".
BCD to decimal, step by step
Read 0111 0011 1001 from BCD.
- Split the bits into groups of four from the right: 0111, 0011, 1001.
- Read each group as one digit: 0111 = 7, 0011 = 3, 1001 = 9.
- Write the digits in order: 739.
A handy check: if you look at a BCD word in hex, the hex digits are the decimal digits. BCD 0010 0101 shows as 16#25, and it means 25.
The common mistake
If a program reads a BCD word as if it were plain binary, it gets the wrong number. BCD 0010 0101 means 25, but as plain binary it is 32 + 4 + 1 = 37. A recipe dialed in as 25 seconds would run for 37. A PLC therefore converts a BCD input before using it, and converts a number to BCD before sending it to a display. On the lab's Allen-Bradley PLC these instructions are FRD (from BCD) and TOD (to BCD). IEC 61131-3 names them BCD_TO_INT and INT_TO_BCD.
Thumbwheels and displays
Each thumbwheel digit has four wires, worth 1, 2, 4 and 8. Each wire goes to one PLC input. So three wheels (000 to 999) take 12 inputs, and four wheels take 16: one whole input module.
A 7-segment display works the other way: four PLC outputs per digit carry the BCD code, and a decoder chip in the display lights the right segments.
Why BCD wastes codes
Four bits have sixteen codes, 0000 to 1111. BCD uses only ten of them. The six codes 1010, 1011, 1100, 1101, 1110 and 1111 (10 to 15) are never valid BCD digits. If a PLC finds one, something is wrong: a broken wire, or a word that was never BCD.
The waste adds up. Sixteen bits in BCD hold 0 to 9,999. The same sixteen bits in plain binary hold 0 to 65,535. BCD is used because it is easy for simple devices, not because it is efficient.
Try it
Open the Exercise tab for six practice questions: write numbers in BCD, read BCD back, spot a code that cannot be BCD, and count the inputs a set of thumbwheels needs. Type BCD answers in groups of four, such as 0010 0101; the spaces are optional.
The questions (on the Exercise tab)
6 questions; the learner needs 80 % to pass and can try again. Practice: a wrong answer shows the right one. The right answers are marked ✓ here only.
Type the answer. Write 47 in BCD, four bits per digit.
✓ 0100 0111 or 100 0111 or 2#0100 0111 or 2#100 0111 or 16#47 (case, spaces and underscores do not matter)
Why: Each digit gets its own four bits: 4 = 0100 and 7 = 0111, so 47 is 0100 0111.
A number. A BCD word reads 1001 0011. What decimal number is it?
✓ 93 (within 0)
Why: Read each group of four as one digit: 1001 = 9 and 0011 = 3, so it is 93.
Choose one. Which group of four bits can never be a BCD digit?
- 0111
- 1001
- ✓ 1100
- 0000
Why: 1100 is 12. A BCD digit is 0 to 9 (0000 to 1001); the codes 1010 to 1111 are never used.
A number. An operator panel has four BCD thumbwheel switches (0000 to 9999). How many PLC inputs do they need?
✓ 16 inputs (within 0)
Why: Each thumbwheel digit has four wires (worth 1, 2, 4 and 8), and each wire needs an input: 4 × 4 = 16.
A number. A thumbwheel is set to 25, so the PLC reads BCD 0010 0101. A program forgets to convert it and reads the bits as plain binary. What number does the program get?
✓ 37 (within 0)
Why: As plain binary, 0010 0101 has 1s in the 32, 4 and 1 places: 32 + 4 + 1 = 37. That is why a BCD input is converted (FRD, or BCD_TO_INT) before it is used.
Type the answer. Write 1950 in BCD, four bits per digit.
✓ 0001 1001 0101 0000 or 1 1001 0101 0000 or 2#0001 1001 0101 0000 or 2#1 1001 0101 0000 or 16#1950 (case, spaces and underscores do not matter)
Why: 1 = 0001, 9 = 1001, 5 = 0101 and 0 = 0000, side by side: 0001 1001 0101 0000.
Your comments on this item
2.3 AND, OR and NOT
about 30 minutes
- Example
- None: this item has no machine.
- Exercise
- Practice questions (below). Passing them completes the item.
- Reference
- Boolean logic, AND and OR with contacts, Contacts
The Learn tab
AND, OR and NOT
A PLC decides what to do by combining signals that are each either TRUE (on, 1) or FALSE (off, 0). A button is pressed or not. A guard is closed or not. A tank is full or not. This kind of on/off math is called Boolean logic, after George Boole, who wrote it down in the 1850s.
Three operations do almost all the work: AND, OR and NOT. Each one has a ladder-logic twin, which you will program in module 5.
AND: every input must be TRUE
AND is TRUE only when all of its inputs are TRUE. If any input is FALSE, the result is FALSE.
The press runs only if the left hand is on its button AND the right hand is on its button AND the guard is closed. Lift one hand, or open the guard, and the press stops.
A truth table lists every combination of the inputs and the result for each. With two inputs there are four combinations, so four rows:
Truth table: A AND B
| A | B | A AND B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE ✓ |
In ladder: normally open contacts, drawn -| |- (XIC on the Allen-Bradley PLC), one after the other, in series. A normally open contact passes power while its tag is TRUE. Power must pass through every contact to reach the coil, so every input must be TRUE. The two-hand press is three contacts in series:
Truth table: LeftHand AND RightHand AND Guard
| LeftHand | RightHand | Guard | LeftHand AND RightHand AND Guard |
|---|---|---|---|
| FALSE | FALSE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| FALSE | TRUE | FALSE | FALSE |
| FALSE | TRUE | TRUE | FALSE |
| TRUE | FALSE | FALSE | FALSE |
| TRUE | FALSE | TRUE | FALSE |
| TRUE | TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE | TRUE ✓ |
Only the last row, where all three are TRUE, lets the press run.
OR: at least one input must be TRUE
OR is TRUE when any input is TRUE, or more than one. It is FALSE only when every input is FALSE.
The horn sounds if the tank level is high OR someone presses the Test button.
Truth table: A OR B
| A | B | A OR B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE ✓ |
| TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | TRUE ✓ |
In ladder: contacts side by side, in parallel. Power can take either path, so one TRUE input is enough. You will meet this again in module 3, where a motor keeps itself running with a contact in parallel with its Start button (the seal-in).
NOT: the opposite
NOT has one input and turns it round: TRUE becomes FALSE, and FALSE becomes TRUE.
The fill valve stays open while the tank is NOT full.
Truth table: NOT A
| A | NOT A |
|---|---|
| FALSE | TRUE ✓ |
| TRUE | FALSE |
In ladder: a normally closed contact, drawn -|/|- (XIO on the Allen-Bradley PLC). It passes power while its tag is FALSE. So a normally closed contact of TankFull, in front of the FillValve coil, opens the valve while the tank is not full.
Putting them together
Real rungs mix all three. The fill valve opens if Auto is on AND the tank is NOT full is Auto AND NOT TankFull: a normally open contact of Auto in series with a normally closed contact of TankFull.
Truth table: Auto AND NOT TankFull
| Auto | TankFull | Auto AND NOT TankFull |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | FALSE |
NOT is worked first. It applies only to the input just after it, here TankFull. The next item covers this order in full.
How it is written
Different books and programs write the same three operations in different ways. They all mean the same thing.
| Operation | In PLC+ and IEC text | In textbooks | In ladder |
|---|---|---|---|
| AND | A AND B |
A · B, or AB | contacts in series |
| OR | A OR B |
A + B | contacts in parallel |
| NOT | NOT A |
Ā (a bar over A), or A′ | a normally closed contact |
Careful: in a textbook A + B means OR, not addition. 1 + 1 is 1 in Boolean logic, because "TRUE OR TRUE" is just TRUE.
Try it
Open the Exercise tab for five practice questions. In the three truth tables, choose TRUE or FALSE as the result of each row. Answer them all, then press Check my answers at the bottom. The last two ask how a press's contacts are wired, and when a normally closed contact passes power. The Reference tab has the three tables and their contacts on one page.
The questions (on the Exercise tab)
5 questions; the learner needs 80 % to pass and can try again. Practice: a wrong answer shows the right one. The right answers are marked ✓ here only.
Fill in a truth table. Fill in A AND B.
Truth table: A AND B
A B A AND B FALSE FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE TRUE TRUE TRUE ✓ Why: AND is TRUE only when both inputs are TRUE: only the last row.
Fill in a truth table. Fill in A OR B.
Truth table: A OR B
A B A OR B FALSE FALSE FALSE FALSE TRUE TRUE ✓ TRUE FALSE TRUE ✓ TRUE TRUE TRUE ✓ Why: OR is FALSE only when both inputs are FALSE: only the first row.
Fill in a truth table. NOT comes first: fill in NOT A AND B.
Truth table: NOT A AND B
A B NOT A AND B FALSE FALSE FALSE FALSE TRUE TRUE ✓ TRUE FALSE FALSE TRUE TRUE FALSE Why: NOT applies to A alone, then AND: TRUE only when A is FALSE and B is TRUE.
Choose one. The press may run only if both hands are on their buttons and the guard is closed. How are the contacts LeftHand, RightHand and Guard wired in the rung?
- ✓ All three in series, one after the other
- All three in parallel, side by side
- LeftHand and RightHand in parallel, then Guard in series
- All three as normally closed contacts
Why: Every condition must be TRUE, so this is AND: LeftHand AND RightHand AND Guard. AND is contacts in series.
Choose one. A rung has a normally closed contact of the tag TankFull. When does that contact pass power?
- While TankFull is TRUE
- ✓ While TankFull is FALSE
- Always
- Only when TankFull changes
Why: A normally closed contact is NOT: it passes power while its tag is FALSE, here while the tank is not full.
Your comments on this item
2.4 Truth tables for larger expressions
about 40 minutes · builds on 2.3
- Example
- None: this item has no machine.
- Exercise
- Practice questions (below). Passing them completes the item.
- Reference
- Boolean logic
The Learn tab
Truth tables for larger expressions
A real rung often has three or four conditions. A truth table shows what it does in every case, before you ever run the machine. This page shows how to build one, which part of an expression is worked first, one more operation (XOR), and how to turn a sentence into an expression.
How many rows
Each input can be FALSE or TRUE, so every new input doubles the number of rows.
| Inputs | Rows |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 2 × 2 × 2 = 8 |
| 4 | 2 × 2 × 2 × 2 = 16 |
To be sure no row is missed, list the rows in counting order: treat FALSE as 0 and TRUE as 1, and count in binary from 000 to 111. The last input changes on every row, the one before it every two rows, and the first input every four rows. PLC+ always lists rows this way, all FALSE first.
Building one, step by step
Write the truth table of (A OR B) AND NOT C.
- There are three inputs, so eight rows. Fill in A, B and C in counting order.
- Add a column for each part, inside out. First
A OR B, thenNOT C. - Combine the parts: the result is TRUE only where both columns are TRUE (AND).
| A | B | C | A OR B | NOT C | Result |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
Here 1 means TRUE and 0 means FALSE. PLC+ draws the same table with the words:
Truth table: (A OR B) AND NOT C
| A | B | C | (A OR B) AND NOT C |
|---|---|---|---|
| FALSE | FALSE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| FALSE | TRUE | FALSE | TRUE ✓ |
| FALSE | TRUE | TRUE | FALSE |
| TRUE | FALSE | FALSE | TRUE ✓ |
| TRUE | FALSE | TRUE | FALSE |
| TRUE | TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | TRUE | FALSE |
Order of operations
In arithmetic, 2 + 3 × 4 is 14, because multiplying comes before adding. Logic has the same kind of rule:
- Brackets first.
- Then NOT, which applies only to the input (or bracket) just after it.
- Then AND.
- Then OR last.
So A OR B AND C means A OR (B AND C), not (A OR B) AND C. The two give different answers. Look at the row where A is TRUE and B and C are FALSE:
Truth table: A OR B AND C
| A | B | C | A OR B AND C |
|---|---|---|---|
| FALSE | FALSE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| FALSE | TRUE | FALSE | FALSE |
| FALSE | TRUE | TRUE | TRUE ✓ |
| TRUE | FALSE | FALSE | TRUE ✓ |
| TRUE | FALSE | TRUE | TRUE ✓ |
| TRUE | TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | TRUE | TRUE ✓ |
Truth table: (A OR B) AND C
| A | B | C | (A OR B) AND C |
|---|---|---|---|
| FALSE | FALSE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| FALSE | TRUE | FALSE | FALSE |
| FALSE | TRUE | TRUE | TRUE ✓ |
| TRUE | FALSE | FALSE | FALSE |
| TRUE | FALSE | TRUE | TRUE ✓ |
| TRUE | TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE | TRUE ✓ |
The first is TRUE on that row; the second is FALSE. When in doubt, write the brackets. They cost nothing and make your meaning plain to the next person who reads the program.
XOR: one or the other, not both
XOR (exclusive OR) is TRUE when its two inputs are different, and FALSE when they are the same.
Truth table: A XOR B
| A | B | A XOR B |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE ✓ |
| TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | FALSE |
A PLC use: a tank has two level sensors at the same height, so they should always agree. Level1 XOR Level2 is TRUE only when they disagree, which means one sensor has failed. That can raise an alarm. PLC+ works XOR after AND and before OR; brackets make it plain.
From a sentence to an expression
Machine requirements come as sentences. Turn them into expressions one phrase at a time.
The alarm sounds if the tank is high or the pump has failed, unless the alarm is silenced.
- Name each condition as a tag: High, PumpFault, Silenced.
- "The tank is high or the pump has failed" is
High OR PumpFault. It is one idea, so put it in brackets. - "Unless the alarm is silenced" means "AND NOT Silenced".
- Together:
(High OR PumpFault) AND NOT Silenced.
Truth table: (High OR PumpFault) AND NOT Silenced
| High | PumpFault | Silenced | (High OR PumpFault) AND NOT Silenced |
|---|---|---|---|
| FALSE | FALSE | FALSE | FALSE |
| FALSE | FALSE | TRUE | FALSE |
| FALSE | TRUE | FALSE | TRUE ✓ |
| FALSE | TRUE | TRUE | FALSE |
| TRUE | FALSE | FALSE | TRUE ✓ |
| TRUE | FALSE | TRUE | FALSE |
| TRUE | TRUE | FALSE | TRUE ✓ |
| TRUE | TRUE | TRUE | FALSE |
Check the table against the sentence: every row with Silenced TRUE is FALSE, and every other row is TRUE when High or PumpFault is. Without the brackets, High OR PumpFault AND NOT Silenced would let a high tank sound the alarm even when silenced.
In ladder (module 5), this is High and PumpFault in parallel, then a normally closed contact of Silenced in series.
Try it
Open the Exercise tab for six practice questions: three truth tables to fill in (choose TRUE or FALSE for each row), the number of rows, the order of operations, and a sentence to match to its expression. Press Check my answers when you have answered them all.
The questions (on the Exercise tab)
6 questions; the learner needs 80 % to pass and can try again. Practice: a wrong answer shows the right one. The right answers are marked ✓ here only.
Fill in a truth table. Fill in (A OR B) AND NOT C.
Truth table: (A OR B) AND NOT C
A B C (A OR B) AND NOT C FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE ✓ FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE ✓ TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE ✓ TRUE TRUE TRUE FALSE Why: Work A OR B and NOT C first, then AND them: TRUE when A or B is TRUE and C is FALSE.
Fill in a truth table. Fill in A XOR B.
Truth table: A XOR B
A B A XOR B FALSE FALSE FALSE FALSE TRUE TRUE ✓ TRUE FALSE TRUE ✓ TRUE TRUE FALSE Why: XOR is TRUE when the two inputs are different: the middle two rows.
A number. How many rows does the truth table of an expression with four inputs have?
✓ 16 rows (within 0)
Why: Each input doubles the rows: 2 × 2 × 2 × 2 = 16.
Choose one. With no brackets written, what does
A OR B AND Cmean?- (A OR B) AND C
- ✓ A OR (B AND C)
- NOT (A OR B) AND C
- It cannot be worked out without brackets
Why: AND is worked before OR, the way multiplying comes before adding: A OR (B AND C).
Choose one. The fan runs if the room is hot and the window is closed, or whenever Override is on. Which expression says this?
- ✓ (Hot AND WindowClosed) OR Override
- Hot AND (WindowClosed OR Override)
- Hot OR WindowClosed AND NOT Override
- NOT (Hot AND WindowClosed AND Override)
Why: "Hot and window closed" is one condition, in brackets; "or whenever Override is on" runs the fan on its own: (Hot AND WindowClosed) OR Override.
Fill in a truth table. The alarm sounds if the tank is high or the pump has failed, unless the alarm is silenced. Fill in its table.
Truth table: (High OR PumpFault) AND NOT Silenced
High PumpFault Silenced (High OR PumpFault) AND NOT Silenced FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE ✓ FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE ✓ TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE ✓ TRUE TRUE TRUE FALSE Why: Every row with Silenced TRUE is FALSE; the other rows are TRUE when High or PumpFault is TRUE.
Your comments on this item
2.5 Module check
about 20 minutes
- Module check
- Complete when every item it covers is: 2.1, 2.2, 2.3, 2.4. Its questions, on the Exercise tab, are below; it is complete when those items are and the questions are passed. Once it is complete, the learner makes the PDF progress report to hand in (Hand in a report).
The Learn tab
Module check: logic and number systems
This check covers the four items of module 2. Each of them is complete once you have passed its practice questions on its Exercise tab.
The check itself is ten questions, on the Exercise tab: numbers to write in binary, hex and BCD, numbers to read back, choices, a match and a truth table. You need 80 % to pass, and you can try again as often as you like. A right answer says why; a wrong one tells you to look again, not what the answer is.
Keep the Reference tab of each item at hand: the 0–15 table, the BCD digits and the logic tables are there. Work on paper if it helps. For a conversion, do it twice, once each way, to check yourself.
When the four items are complete and you have passed the questions, the module is complete and ready to hand in: Hand in a report (the second row of the path) makes the PDF progress report for your instructor.
The questions (on the Exercise tab)
10 questions; the learner needs 80 % to pass and can try again. A wrong answer says “not quite, look again”; the reason is shown once the answer is right. The right answers are marked ✓ here only.
Type the answer. Write 89 in binary.
✓ 1011001 (89 in binary; leading zeros, spaces and marks such as 16# or 0x are accepted)
Why: 89 = 64 + 16 + 8 + 1, so the 64, 16, 8 and 1 places hold 1s: 101 1001 (2#0101_1001 as eight bits).
Type the answer. Write 250 in hexadecimal.
✓ FA (250 in hexadecimal; leading zeros, spaces and marks such as 16# or 0x are accepted)
Why: 250 ÷ 16 = 15 remainder 10. 15 is F and 10 is A, so 250 is 16#FA. Check: 15 × 16 + 10 = 250.
A number. A module reports the status word
16#1A4. What is it in decimal?✓ 420 (within 0)
Why: 1 × 256 + A (10) × 16 + 4 = 256 + 160 + 4 = 420. In binary it is 0001 1010 0100.
Type the answer. Write 59 in BCD, four bits per digit.
✓ 0101 1001 or 101 1001 or 2#0101 1001 or 2#101 1001 or 16#59 (case, spaces and underscores do not matter)
Why: Each digit gets its own four bits: 5 = 0101 and 9 = 1001, so 59 is 0101 1001.
A number. Three thumbwheel switches send the BCD bits 0110 0000 0100. What number is dialed?
✓ 604 (within 0)
Why: Read each group of four as one digit: 0110 = 6, 0000 = 0, 0100 = 4, so 604.
Choose one. In plain binary, 16 bits hold 0 to 65,535. Why do the same 16 bits in BCD hold only 0 to 9,999?
- ✓ Each group of four bits holds only one digit, 0 to 9; the codes 1010 to 1111 are never used
- BCD uses one of the 16 bits for the sign
- BCD needs 8 bits for each digit
- A PLC cannot count past 9,999
Why: Four bits have sixteen codes but BCD uses only ten of them, so 16 bits make four digits: 0000 to 9999.
Match each one. Match each logic operation to the contacts that make it in a ladder rung.
AND→ Contacts in series, one after the otherOR→ Contacts in parallel, side by sideNOT→ A normally closed contact
Why: In series, power must pass every contact (AND); in parallel, any path will do (OR); a normally closed contact passes power while its tag is FALSE (NOT).
Choose one. The horn sounds if the tank level is high or someone presses Test. A normally open contact of each tag is used. How are the two contacts wired?
- In series
- ✓ In parallel
- Test as a normally closed contact in series with High
- Only one contact is needed
Why: Either condition alone sounds the horn, so this is OR: contacts in parallel.
Choose one. The conveyor runs in two cases: when Run is on and the jam sensor is not blocked; or, on its own, while Jog is held. The jam sensor's tag Jam is TRUE when blocked. Which expression says this?
- ✓ (Run AND NOT Jam) OR Jog
- Run AND NOT (Jam OR Jog)
- Run AND (NOT Jam OR Jog)
- NOT (Run AND Jam) OR Jog
Why: "Run is on and the jam sensor is not blocked" is Run AND NOT Jam, one condition in brackets; Jog alone also runs it: (Run AND NOT Jam) OR Jog.
Fill in a truth table. Mind the order of operations: fill in A AND B OR NOT C.
Truth table: A AND B OR NOT C
A B C A AND B OR NOT C FALSE FALSE FALSE TRUE ✓ FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE ✓ FALSE TRUE TRUE FALSE TRUE FALSE FALSE TRUE ✓ TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE ✓ TRUE TRUE TRUE TRUE ✓ Why: NOT first, then AND, then OR: (A AND B) OR (NOT C). TRUE whenever C is FALSE, and on the row where A, B and C are all TRUE.