What Happens to My Code

Data Processing and Binary Logic

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.

Hollerith Machine

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
Punch card

Punch Card Example

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:

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.

Logic gate symbols

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;
    

Resources