Why do computers only know 0 and 1
In this lecture, you will understand: why computers chose binary instead of decimal, and how this choice determined the entire architecture of modern computers.
Start with switches
Imagine there is a row of light switches in front of you.
Each switch has only two states:openorclose。
You cannot make a switch "half-open" or "open 37%" — it is bistable, with no intermediate state.
The most basic component inside a computer — the transistor — is essentially the same kind of thing as a switch.
It has only two stable states:Conducting (powered)andCutoff (powered off)。
Two States of Voltage
In digital circuits, we assign a symbol to each of these two states:
- High voltage (e.g., 3.3V or 5V) represents1
- Low voltage (close to 0V) represents0
The relationship between voltage and binary
The color band below simulates the voltage range of a transistor from 0V to 3.3V, intuitively showing the relationship between logic 0, logic 1, and the forbidden zone.
Logic 0 0.5V 1.0V 1.5V
forbidden zone 1.8V
start 2.1V 2.7V 3.3V
Logic 1
Logic 0 range: 0.0V ~ 1.5V (blue region) | Forbidden zone: 1.5V ~ 1.8V (gray region, signals do not stay) | Logic 1 range: 1.8V ~ 3.3V (orange region)
Note: the circuit does not need to precisely measure the voltage value; it only needs to determine "high or low".
This is much easier than judging "what number it is."
Why not use decimal
Humans use the decimal system because we have ten fingers.
But why can't computers use decimal?
Reason one: Extremely difficult to implement in engineering
To make a circuit represent the 10 digits of decimal (0~9), the circuit needs to precisely distinguish 10 different voltage levels.
For example: 0V = 0, 0.33V = 1, 0.66V = 2, ..., 3.3V = 9.
Here's the problem: signals experience loss and interference during transmission.
Suppose you send 0.66V to represent the digit 2, but when it arrives the voltage becomes 0.71V.
The receiving end would be confused: is this 2 (0.66V) or 3 (0.99V)?
Reason two: Binary is naturally noise-resistant
Binary only needs to distinguish two states, giving it a huge margin for error.
As shown: the range of logic 0 is 0~1.5V, and the range of logic 1 is 1.8V~3.3V.
There is a 0.3V protection zone in the middle.
Even if the signal has large fluctuations, as long as it does not cross the protected zone, the data will not be corrupted.
Reason three: Perfect fit with mathematics
0 and 1 correspond exactly to "false" and "true" in Boolean algebra.
Boolean algebra (logical operations such as AND, OR, NOT) has a complete mathematical theory.
Engineers can use this theory to design, analyze, and optimize circuits — this is a very fortunate thing.
Computers choosing binary is not accidental. It is the result of engineering constraints (easy to implement), physical characteristics (noise resistance), and mathematical tools (Boolean algebra) working together.
Bits and bytes—the basic units of information
A binary digit is called 1 bitbit(bit), it can only represent 0 or 1.
Clearly, a single bit can represent too little information.
So we combine 8 bits together and call it 1byte(byte).
How many different values can a byte represent?
Each bit has 2 choices (0 or 1), so the number of combinations of 8 bits is:
2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 28 = 256
That is, from 00000000 (decimal 0) to 11111111 (decimal 255), a total of 256 different values.
| byte count | The range of representable values | Common uses |
|---|---|---|
| 1 byte (8 bits) | 0 ~ 255 | An ASCII character, a channel value in an RGB color |
| 2 bytes (16 bit) | 0 ~ 65,535 | Port number, register size of early CPUs |
| 4 bytes (32 bit) | 0 ~ 4,294,967,295 | IPv4 addresses, int type |
| 8 bytes (64 bit) | 0 ~ approx. 1.8 x 1019 | Word length of modern CPUs, long type |
Interactive demo: a one-byte light bulb simulator
The interactive panel below lets you intuitively see how 8 bits combine to form any value from 0 to 255.
Each light bulb represents one bit.Click the bulb to toggle 0/1 state, and the corresponding decimal value is displayed in real time on the right.
Light bulb simulator: one byte = 8 bits
Click a light bulb to toggle its state, and observe how binary maps to decimal.
Look carefully at the weight labels below each light bulb.
The leftmost bulb has the largest weight (128), and the rightmost has the smallest weight (1).
This is the idea of "expansion by weight"—multiply the value at each position by its weight, and add them all together to get the final result.
Understanding binary with code
Python has built-in support for binary, so we can directly use it to verify the light bulb demo above.
Example
# 1. View the binary representation of a number
print("Decimal → Binary:")
for n in [0, 1, 2, 7, 8, 15, 16, 42, 65, 97, 127, 255]:
# bin() returns the '0b...' format; use [2:] to remove the prefix.
# zfill(8) pad to 8 bits
print(f" {n:3d} → {bin(n)[2:].zfill(8)}")
print()
# 2. Parse binary string to decimal
print("Binary → Decimal:")
binary_strings = ["00000000", "01000001", "01100001", "11111111"]
for b in binary_strings:
# int(string, 2) Converts a binary string to an integer.
dec = int(b, 2)
print(f" {b} → {dec:3d}")
print()
# 3. Verify: one byte has exactly 256 values
print("The range of a byte:")
print(fMinimum value: {int('00000000', 2)})
print(fMaximum value: {int('11111111', 2)})
print(fTotal count: {int('11111111', 2) - int('00000000', 2) + 1})
print()
# 4. Bitwise Operations: AND, OR, Left Shift, Right Shift
print("Bitwise operation example:")
a = 0b0011 # 3
b = 0b0101 # 5
print(f{bin(a)} & {bin(b)} = {bin(a & b)} (bitwise AND))
print(f{bin(a)} | {bin(b)} = {bin(a | b)} (bitwise OR))
print(f{bin(a)} << 1 = {bin(a << 1)} (shift left by 1 bit, equivalent to multiplying by 2))
print(f{bin(b)} >> 1 = {bin(b >> 1)} (shift right by 1 bit, equivalent to dividing by 2))
print()
# 5. EXAMPLE test string
text = "EXAMPLE"
print(fThe binary representation of each character in the string '{text}':)
for ch in text:
ascii_val = ord(ch)
print(f" '{ch}' → ASCII={ascii_val:3d} → binary={bin(ascii_val)[2:].zfill(8)}")
Why binary is the foundation of "information representation"
Once you understand binary, you understand a key fact:
Everything inside a computer—numbers, text, images, sound, video—is ultimately stored and processed in the form of 0s and 1s.
In the following lectures, you will see:
- Lecture 2: How to convert between different bases
- Lecture 3: how negative numbers are represented in binary (two's complement)
- Lecture 4: how decimals are represented in binary (floating point)
- Lecture 5: how text is represented in binary (character encoding)
All of these are built on the foundation that "everything is 0s and 1s."
other extensionsThe core conclusion of all 5 lectures in this module: computers do not "understand" information; rather, through ingenious encoding rules, they map everything in the world into combinations of 0s and 1s.