Punch card processing
Before modern computers, data processing was done using mechanical systems. One of the most influential was Herman Hollerith’s tabulating machine, used in the 1890 U.S. Census. It relied on punch cards to represent data and electrical contacts to 'read' the presence or absence of holes.
Each column on a card represented a category (e.g., age, gender), and each row a person. A punched hole allowed an electric circuit to complete, registering a count — essentially a binary 1. No hole = 0. This is one of the earliest examples of binary data encoding in a machine-readable format.
Punch Card Example
Gender: Male = Punch at column 3 → 00010000
Age Group: 20–29 = Punch at column 5 → 00100000
Boolean Logic in Machinery
Mechanical and electrical systems like Hollerith’s also embodied Boolean logic — the foundation of computing. Here's how:
- AND: Two levers must be pressed (circuits closed) to complete a third circuit → output = 1 only if both inputs are 1.
- OR: Either of two switches completes the circuit.
- NOT: Mechanically reversing the input (e.g., spring-loaded blocking switch).
Truth Tables
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
Boolean logic in electrical diagrams
When drawing an electrical diagram, special symbols are used to represent boolean logic. These are known as logic gates. Usually, these are implemented in a chip, since in reality they need several parts (such as transistors and diodes) to implement.
Byte logic
When applying boolean logic to byte data, it helps select or move bits around. If each bit represents a specific attribute, we refer to these as flags. Then we can use logic operators to process these flags.
// Using AND means masking flags
int a = 0b1010 & 0b0011;
assert a == 0b0010;
// Using OR means adding flags
int b = 0b1010 | 0b0011;
assert b == 0b1011;
// Bit shifts, perhaps combined with AND, can be used to select multiple bits in a byte
int c = 0b1010 >> 1;
assert c == 0b0101;