Skip to content
Book 6: Algorithms, Programming and Logic

Book 6 · Chapter 10

Boolean logic

§10Core · ≈ 8.9 m · →B6·10

This chapter is in the ebook.

Read it in full on cswithzak.com. Every question has its mark scheme and every program is ready to run. The free practice for each section is below, with the short code the book prints beside it.

Open in the ebook

For the whole chapter

§10

Short code B6·10·1

Two states: 1 and 0

Short code B6·10·10

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

NOT, AND and OR

Short code B6·10·11

AND

Output

Expression: X = A AND B   (Cambridge notation: X = A.B)
2 inputs → 4 rows, counting up in binary from 00.
A | B | X
--+---+--
0 | 0 | 0
0 | 1 | 0
1 | 0 | 0
1 | 1 | 1
X = 1 on row 11.
Sum-of-products from the 1 rows: X = A.B
Run and checked before printing
OR

Output

Expression: X = A OR B   (Cambridge notation: X = A + B)
2 inputs → 4 rows, counting up in binary from 00.
A | B | X
--+---+--
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 1
X = 1 on rows 01, 10, 11.
Sum-of-products from the 1 rows: X = A̅.B + A.B̅ + A.B
Run and checked before printing
NOT

Output

Expression: X = NOT A   (Cambridge notation: X = A̅)
1 input → 2 rows, counting up in binary from 0.
A | X
--+--
0 | 1
1 | 0
X = 1 on row 0.
Sum-of-products from the 1 rows: X = A̅
Run and checked before printing

NAND, NOR and XOR

Short code B6·10·12

NAND

Output

Expression: X = A NAND B   (Cambridge notation: X = A NAND B)
2 inputs → 4 rows, counting up in binary from 00.
A | B | X
--+---+--
0 | 0 | 1
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0
X = 1 on rows 00, 01, 10.
Sum-of-products from the 1 rows: X = A̅.B̅ + A̅.B + A.B̅
Run and checked before printing
NOR

Output

Expression: X = A NOR B   (Cambridge notation: X = A NOR B)
2 inputs → 4 rows, counting up in binary from 00.
A | B | X
--+---+--
0 | 0 | 1
0 | 1 | 0
1 | 0 | 0
1 | 1 | 0
X = 1 on row 00.
Sum-of-products from the 1 rows: X = A̅.B̅
Run and checked before printing
XOR

Output

Expression: X = A XOR B   (Cambridge notation: X = A ⊕ B)
2 inputs → 4 rows, counting up in binary from 00.
A | B | X
--+---+--
0 | 0 | 0
0 | 1 | 1
1 | 0 | 1
1 | 1 | 0
X = 1 on rows 01, 10.
Sum-of-products from the 1 rows: X = A̅.B + A.B̅
Run and checked before printing

The six gates side by side

Short code B6·10·13

The prediction circuit (A = 1, B = 1, C = 0 is row 110)

Output

Expression: X = (A XOR B) NOR C   (Cambridge notation: X = A ⊕ B NOR C)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | A XOR B | X
--+---+---+---------+--
0 | 0 | 0 | 0       | 1
0 | 0 | 1 | 0       | 0
0 | 1 | 0 | 1       | 0
0 | 1 | 1 | 1       | 0
1 | 0 | 0 | 1       | 0
1 | 0 | 1 | 1       | 0
1 | 1 | 0 | 0       | 1
1 | 1 | 1 | 0       | 0
X = 1 on rows 000, 110.
Sum-of-products from the 1 rows: X = A̅.B̅.C̅ + A.B.C̅
Run and checked before printing

Logic expressions

Short code B6·10·14

B OR NOT C

Output

Expression: X = B OR NOT C   (Cambridge notation: X = B + C̅)
2 inputs → 4 rows, counting up in binary from 00.
B | C | NOT C | X
--+---+-------+--
0 | 0 | 1     | 1
0 | 1 | 0     | 0
1 | 0 | 1     | 1
1 | 1 | 0     | 1
X = 1 on rows 00, 10, 11.
Sum-of-products from the 1 rows: X = B̅.C̅ + B.C̅ + B.C
Run and checked before printing
NOT (B OR C)

Output

Expression: X = NOT (B OR C)   (Cambridge notation: X = B̅ ̅+̅ ̅C̅)
2 inputs → 4 rows, counting up in binary from 00.
B | C | B OR C | X
--+---+--------+--
0 | 0 | 0      | 1
0 | 1 | 1      | 0
1 | 0 | 1      | 0
1 | 1 | 1      | 0
X = 1 on row 00.
Sum-of-products from the 1 rows: X = B̅.C̅
Run and checked before printing

From an expression to a circuit

Short code B6·10·15

Mark Ladder: X = (A NOR B) AND (B XOR C)

Output

Expression: X = (A NOR B) AND (B XOR C)   (Cambridge notation: X = (A NOR B).(B ⊕ C))
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | A NOR B | B XOR C | X
--+---+---+---------+---------+--
0 | 0 | 0 | 1       | 0       | 0
0 | 0 | 1 | 1       | 1       | 1
0 | 1 | 0 | 0       | 1       | 0
0 | 1 | 1 | 0       | 0       | 0
1 | 0 | 0 | 0       | 0       | 0
1 | 0 | 1 | 0       | 1       | 0
1 | 1 | 0 | 0       | 1       | 0
1 | 1 | 1 | 0       | 0       | 0
X = 1 on row 001.
Sum-of-products from the 1 rows: X = A̅.B̅.C
Run and checked before printing
Faded twin: X = (A OR NOT C) NAND B

Output

Expression: X = (A OR NOT C) NAND B   (Cambridge notation: X = (A + C̅) NAND B)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | NOT C | A OR NOT C | X
--+---+---+-------+------------+--
0 | 0 | 0 | 1     | 1          | 1
0 | 0 | 1 | 0     | 0          | 1
0 | 1 | 0 | 1     | 1          | 0
0 | 1 | 1 | 0     | 0          | 1
1 | 0 | 0 | 1     | 1          | 1
1 | 0 | 1 | 0     | 1          | 1
1 | 1 | 0 | 1     | 1          | 0
1 | 1 | 1 | 0     | 1          | 0
X = 1 on rows 000, 001, 011, 100, 101.
Sum-of-products from the 1 rows: X = A̅.B̅.C̅ + A̅.B̅.C + A̅.B.C + A.B̅.C̅ + A.B̅.C
Run and checked before printing

Completing a truth table

Short code B6·10·16

X = (A AND B) OR NOT C, with working columns

Output

Expression: X = (A AND B) OR NOT C   (Cambridge notation: X = A.B + C̅)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | A AND B | NOT C | X
--+---+---+---------+-------+--
0 | 0 | 0 | 0       | 1     | 1
0 | 0 | 1 | 0       | 0     | 0
0 | 1 | 0 | 0       | 1     | 1
0 | 1 | 1 | 0       | 0     | 0
1 | 0 | 0 | 0       | 1     | 1
1 | 0 | 1 | 0       | 0     | 0
1 | 1 | 0 | 1       | 1     | 1
1 | 1 | 1 | 1       | 0     | 1
X = 1 on rows 000, 010, 100, 110, 111.
Sum-of-products from the 1 rows: X = A̅.B̅.C̅ + A̅.B.C̅ + A.B̅.C̅ + A.B.C̅ + A.B.C
Run and checked before printing
Mark Ladder: X = (A XOR B) AND NOT C

Output

Expression: X = (A XOR B) AND NOT C   (Cambridge notation: X = (A ⊕ B).C̅)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | A XOR B | NOT C | X
--+---+---+---------+-------+--
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 | 0       | 1     | 0
1 | 1 | 1 | 0       | 0     | 0
X = 1 on rows 010, 100.
Sum-of-products from the 1 rows: X = A̅.B.C̅ + A.B̅.C̅
Run and checked before printing
Faded twin: X = (A OR B) NAND C

Output

Expression: X = (A OR B) NAND C   (Cambridge notation: X = (A + B) NAND C)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | A OR B | X
--+---+---+--------+--
0 | 0 | 0 | 0      | 1
0 | 0 | 1 | 0      | 1
0 | 1 | 0 | 1      | 1
0 | 1 | 1 | 1      | 0
1 | 0 | 0 | 1      | 1
1 | 0 | 1 | 1      | 0
1 | 1 | 0 | 1      | 1
1 | 1 | 1 | 1      | 0
X = 1 on rows 000, 001, 010, 100, 110.
Sum-of-products from the 1 rows: X = A̅.B̅.C̅ + A̅.B̅.C + A̅.B.C̅ + A.B̅.C̅ + A.B.C̅
Run and checked before printing

From a circuit to an expression and a truth table

Short code B6·10·17

Circuit to expression: X = (NOT A OR B) XOR (B NAND C)

Output

Expression: X = (NOT A OR B) XOR (B NAND C)   (Cambridge notation: X = (A̅ + B) ⊕ B NAND C)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | NOT A | NOT A OR B | B NAND C | X
--+---+---+-------+------------+----------+--
0 | 0 | 0 | 1     | 1          | 1        | 0
0 | 0 | 1 | 1     | 1          | 1        | 0
0 | 1 | 0 | 1     | 1          | 1        | 0
0 | 1 | 1 | 1     | 1          | 0        | 1
1 | 0 | 0 | 0     | 0          | 1        | 1
1 | 0 | 1 | 0     | 0          | 1        | 1
1 | 1 | 0 | 0     | 1          | 1        | 0
1 | 1 | 1 | 0     | 1          | 0        | 1
X = 1 on rows 011, 100, 101, 111.
Sum-of-products from the 1 rows: X = A̅.B.C + A.B̅.C̅ + A.B̅.C + A.B.C
Run and checked before printing

From a problem statement

Short code B6·10·18

Greenhouse pump: P = (D AND NOT E) OR M

Output

Expression: X = (D AND NOT E) OR M   (Cambridge notation: X = D.E̅ + M)
3 inputs → 8 rows, counting up in binary from 000.
D | E | M | NOT E | D AND NOT E | X
--+---+---+-------+-------------+--
0 | 0 | 0 | 1     | 0           | 0
0 | 0 | 1 | 1     | 0           | 1
0 | 1 | 0 | 0     | 0           | 0
0 | 1 | 1 | 0     | 0           | 1
1 | 0 | 0 | 1     | 1           | 1
1 | 0 | 1 | 1     | 1           | 1
1 | 1 | 0 | 0     | 0           | 0
1 | 1 | 1 | 0     | 0           | 1
X = 1 on rows 001, 011, 100, 101, 111.
Sum-of-products from the 1 rows: X = D̅.E̅.M + D̅.E.M + D.E̅.M̅ + D.E̅.M + D.E.M
Run and checked before printing
Faded twin: G = D AND (M XOR S)

Output

Expression: X = D AND (M XOR S)   (Cambridge notation: X = D.(M ⊕ S))
3 inputs → 8 rows, counting up in binary from 000.
D | M | S | M XOR S | X
--+---+---+---------+--
0 | 0 | 0 | 0       | 0
0 | 0 | 1 | 1       | 0
0 | 1 | 0 | 1       | 0
0 | 1 | 1 | 0       | 0
1 | 0 | 0 | 0       | 0
1 | 0 | 1 | 1       | 1
1 | 1 | 0 | 1       | 1
1 | 1 | 1 | 0       | 0
X = 1 on rows 101, 110.
Sum-of-products from the 1 rows: X = D.M̅.S + D.M.S̅
Run and checked before printing

From a truth table to an expression or a circuit

Short code B6·10·19

Truth table to expression: X = (NOT A AND B) OR (A AND NOT B)

Output

Expression: X = (NOT A AND B) OR (A AND NOT B)   (Cambridge notation: X = A̅.B + A.B̅)
2 inputs → 4 rows, counting up in binary from 00.
A | B | NOT A | NOT A AND B | NOT B | A AND NOT B | X
--+---+-------+-------------+-------+-------------+--
0 | 0 | 1     | 0           | 1     | 0           | 0
0 | 1 | 1     | 1           | 0     | 0           | 1
1 | 0 | 0     | 0           | 1     | 1           | 1
1 | 1 | 0     | 0           | 0     | 0           | 0
X = 1 on rows 01, 10.
Sum-of-products from the 1 rows: X = A̅.B + A.B̅
Run and checked before printing
Three inputs: 1s in rows 001 and 011

Output

Expression: X = (NOT A AND NOT B AND C) OR (NOT A AND B AND C)   (Cambridge notation: X = A̅.B̅.C + A̅.B.C)
3 inputs → 8 rows, counting up in binary from 000.
A | B | C | NOT A | NOT B | NOT A AND NOT B AND C | NOT A AND B AND C | X
--+---+---+-------+-------+-----------------------+-------------------+--
0 | 0 | 0 | 1     | 1     | 0                     | 0                 | 0
0 | 0 | 1 | 1     | 1     | 1                     | 0                 | 1
0 | 1 | 0 | 1     | 0     | 0                     | 0                 | 0
0 | 1 | 1 | 1     | 0     | 0                     | 1                 | 1
1 | 0 | 0 | 0     | 1     | 0                     | 0                 | 0
1 | 0 | 1 | 0     | 1     | 0                     | 0                 | 0
1 | 1 | 0 | 0     | 0     | 0                     | 0                 | 0
1 | 1 | 1 | 0     | 0     | 0                     | 0                 | 0
X = 1 on rows 001, 011.
Sum-of-products from the 1 rows: X = A̅.B̅.C + A̅.B.C
Run and checked before printing
The shorter expression with the same table

Output

Expression: X = NOT A AND C   (Cambridge notation: X = A̅.C)
2 inputs → 4 rows, counting up in binary from 00.
A | C | NOT A | X
--+---+-------+--
0 | 0 | 1     | 0
0 | 1 | 1     | 1
1 | 0 | 0     | 0
1 | 1 | 0     | 0
X = 1 on row 01.
Sum-of-products from the 1 rows: X = A̅.C
Run and checked before printing

Logic in your programs

Short code B6·10·20

DECLARE Row : INTEGER
DECLARE A : INTEGER
DECLARE B : INTEGER
DECLARE C : INTEGER
DECLARE X : INTEGER
OUTPUT "A B C X"
FOR Row ← 0 TO 7
    A ← DIV(Row, 4)
    B ← MOD(DIV(Row, 2), 2)
    C ← MOD(Row, 2)
    IF (A = 1 AND B = 1) OR NOT (C = 1)
      THEN
        X ← 1
      ELSE
        X ← 0
    ENDIF
    OUTPUT A, " ", B, " ", C, " ", X
NEXT Row
A program that completes the truth table for X = (A AND B) OR NOT C. Each row number from 0 to 7 is split into its three bits.

Output

A B C X
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
Run and checked before printing

Command-word coach

Short code B6·10·21

Practice for this page of the book: the quiz, flashcards and past-paper questions for its section are listed above.

Workbook: Boolean logic

Short code W6·10 · Algorithms, Programming and Logic Workbook

The write-in workbook for this chapter has drills, exam-style practice, trace tables, fix-the-mistake and mark-it-yourself pages. Its full mark schemes and an interactive version arrive here with the chapter.

Ask Z about Boolean logic
Buy ZAK's books — WhatsApp the books desk: Buy the booksPrint or ebook