Boolean Operators
Understanding Boolean Logic
Boolean logic
A branch of algebra that deals with true or false values, represented as 1 and 0 in binary systems
It forms the foundation of digital circuits, programming, and algorithm design.
NoteBoolean logic is named after George Boole, a 19th-century mathematician who developed the algebraic system that underpins modern computing.
The Role of Boolean Operators
Boolean operators are used to perform logical operations on binary values.
They are essential for:
- Decision-making in algorithms
- Control flow in programming
- Designing digital circuits
- Think of Boolean operators as traffic lights for data.
- They control the flow of information, determining which paths are open (true) or closed (false) based on specific conditions.
Core Boolean Operators
Before diving into different Boolean operators, we need to understand how to visualise them.
Truth table
A tool to show all possible combinations of input values (usually true or false) and their corresponding output for a logical operation or Boolean expression
Truth tables are used to represent the behaviour of Boolean operators. They list all possible input combinations and their corresponding outputs. They consist of:
- Inputs: Represent all possible combinations of Boolean values (0 or 1) for the given variables.
- Outputs: Show the result of applying a Boolean expression or operator to the inputs.
- Think of a truth table as a recipe.
- Each row is a step that shows what happens when you combine specific ingredients (inputs) to produce a dish (output).
Another way is to draw a corresponding logic gate diagram:
Logic gates
Logic gates are the building blocks of digital circuits. They perform Boolean operations on one or more binary inputs to produce a single binary output.
Logic diagrams
Logic diagrams are visual representations of how logic gates are connected and interact within a circuit.
Each core operator has their own standard symbol for representing a Boolean operator.
AND Operator
- Symbol: ∧ or *
- Function: Returns true (1) only if both inputs are true (1).
- Corresponding truth table and logic diagram:
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |

When using the AND operator in programming, remember that all conditions must be true for the overall expression to evaluate as true.
ExampleIn Python, and operator is straightforwardly called "and":
def and_operator(a, b):
if a == 1 and b == 1:
result = 1
else:
result = 0
return resultOR Operator
- Symbol: ∨ or +
- Function: Returns true (1) if at least one input is true (1).
- Corresponding truth table and logic diagram:
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |

The OR operator is inclusive, meaning it returns true if one or both inputs are true.
ExampleIn Python, or operator is straightforwardly called "or":
def or_operator(a, b):
if a == 1 or b == 1:
result = 1
else:
result = 0
return resultNOT Operator
- Symbol: ¬ or !
- Function: Inverts the input, returns true (1) if the input is false (0), and vice versa.
- Corresponding truth table and logic diagram:
| Input | Output |
|---|---|
| 0 | 1 |
| 1 | 0 |

The not operator is unary, meaning it operates on a single input.
AnalogyYou can also refer to the not operator as the negation of or inverting a statement.
More Sophisticated Boolean Operators
NAND Operator (not and)
- Symbol: ¬(A ∧ B) or A * B
- Function: Returns false (0) only if both inputs are true (1).
- Corresponding truth table:
| Input A | Input B | Output |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |