Sub topic 1
Boolean Values and Operators
Boolean algebra works with variables that have only two values: 0 and 1. In digital logic, 0 usually means false or low voltage, and 1 means true or high voltage. A Boolean expression combines variables with logical operators to produce another Boolean value.
Prerequisites
This chapter assumes that you can convert between binary and decimal numbers, recognize basic logic gates, and read the notation of propositional and set logic. The symbols below are common in digital logic:
- \(A + B\) means \(A\) OR \(B\).
- \(A \cdot B\), or simply \(AB\), means \(A\) AND \(B\).
- \(\overline{A}\), \(A'\), or NOT \(A\) means the complement of \(A\).
- \(A \oplus B\) means \(A\) XOR \(B\).
A Boolean variable is different from an ordinary integer variable. Addition in Boolean algebra is OR, and multiplication is AND. Therefore, \(1 + 1 = 1\), not 2.
The basic operators
AND produces 1 only when every input is 1. OR produces 1 when at least one input is 1. NOT reverses its input. XOR produces 1 when its two inputs are different.
| A | B | A AND B | A OR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
For NOT, \(\overline{0}=1\) and \(\overline{1}=0\).
When an expression contains several operators, use parentheses when possible. Without parentheses, a common precedence order is NOT first, AND second, and OR last. Thus,
\[ \overline{A} + BC \]
means \((\text{NOT }A)\) OR \((B\text{ AND }C)\).
def boolean_expression(a, b, c):
# NOT has been written explicitly to make the precedence clear.
return (not a) or (b and c)
for a in (False, True):
for b in (False, True):
for c in (False, True):
result = int(boolean_expression(a, b, c))
print(int(a), int(b), int(c), result)The output contains one row for every assignment of \(A\), \(B\), and \(C\). With \(n\) Boolean variables, a complete truth table has \(2^n\) rows.
Reading expressions as circuits
Each operator corresponds to a gate. For example, \(F=AB+\overline{C}\) can be built with:
- An AND gate for \(A\) and \(B\).
- A NOT gate for \(C\).
- An OR gate combining those two results.
A circuit and its Boolean expression describe the same function. This connection lets you analyze a circuit with a truth table and later simplify it with Boolean laws or Karnaugh maps.
Exercise
For \(F(A,B)=A\oplus B\), which input rows produce \(F=1\)?
Show answer
The rows \(A=0,B=1\) and \(A=1,B=0\). XOR is 1 exactly when its inputs differ.