Why Computers Only Understand 0 and 1
In this lecture you will understand: why computers chose binary rather than decimal, and how this choice determined the entire architecture of modern computers.
Starting with switches
Imagine a row of light switches in front of you.
Each switch has only two states: on or off.
You cannot make a switch 'half on' or '37% on' - it is two-state, 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: conduction (power on) and cutoff (power off).
The two states of voltage
In digital circuits, we assign a symbol to each of these two states:
- A high voltage (e.g. 3.3V or 5V) represents 1
- A low voltage (close to 0V) represents 0
The relationship between voltage and binary
The color band below simulates the voltage range of a transistor from 0V to 3.3V, visually showing the relationship between logic 0, logic 1, and the forbidden zone.
0.0V
Logic 0
.
0.5V
1.0V
1.5V
Forbidden zone
1.8V
at the beginning
2.1V
2.7V
3.3V
Logic 1
Logic 0 range: 0.0V ~ 1.5V (blue area) | Forbidden zone: 1.5V ~ 1.8V (gray area, signals do not stay here) | Logic 1 range: 1.8V ~ 3.3V (orange area)
Note: the circuit does not need to measure the voltage precisely; it only needs to judge 'high or low'.
This is much easier than judging 'what exact value it is'.
Why not use decimal
Humans use decimal because we have ten fingers.
But why can't computers use decimal?
Reason one: extremely difficult to implement in engineering
If a circuit had to represent the 10 decimal digits (0~9), it would need to precisely distinguish 10 different voltage levels.
For example: 0V = 0, 0.33V = 1, 0.66V = 2, ..., 3.3V = 9.
Here comes the problem: signals suffer loss and interference during transmission.
Suppose you send 0.66V to represent the digit 2, but by the time it reaches its destination the voltage has become 0.71V.
The receiving end gets confused: is this 2 (0.66V) or 3 (0.99V)?
Reason two: binary is naturally resistant to interference
Binary only needs to distinguish two states, so the tolerance for error is huge.
As shown: the logic 0 range is 0~1.5V, and the logic 1 range is 1.8V~3.3V.
There is a 0.3V guard band in between.
Even if the signal fluctuates considerably, as long as it does not cross the guard band, the data will not be corrupted.
Reason three: a perfect fit with mathematics
0 and 1 correspond exactly to 'false' and 'true' in Boolean algebra.
Boolean algebra (logic operations such as AND, OR, NOT) has a complete mathematical theory.
Engineers can use this theory to design, analyze, and optimize circuits - a very fortunate thing.
The computer's choice of binary is no accident. It is the combined result of three factors: engineering constraints (easy to implement), physical properties (interference resistance), and mathematical tools (Boolean algebra).
Bits and bytes - the basic units of information
One binary digit is called 1 bit, and it can represent only 0 or 1.
Obviously, a single bit carries far too little information.
So we group 8 bits together and call it 1 byte.
How many different values can one 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), giving 256 different values in total.
| Number of bytes | Range of representable values | Common Use Cases |
|---|---|---|
| 1 byte (8 bit) | 0 ~ 255 | One ASCII character, one channel value of an RGB color |
| 2 bytes (16 bit) | 0 ~ 65,535 | Port numbers, register size of early CPUs |
| 4 bytes (32 bit) | 0 ~ 4,294,967,295 | IPv4 address, int type |
| 8 bytes (64 bit) | 0 ~ about 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 feel how 8 bits combine into any value between 0 and 255.
Each bulb represents one bit. Click a bulb to toggle its 0/1 state, and the right side shows the corresponding decimal value in real time.
Light-bulb simulator: one byte = 8 bits
Click the bulbs to toggle states and observe how binary maps to decimal.
Decimal:
0
Binary:
00000000
Look carefully at the weight label beneath each bulb.
The leftmost bulb has the largest weight (128), and the rightmost has the smallest (1).
This is the idea of 'expansion by weight' - the value at each position multiplied by its weight, all added together, gives the final result.
Understanding binary with code
Python has built-in support for binary, so we can use it directly to verify the light-bulb demo above.
Example
Basic binary operations (runoob demo)
1. View the binary representation of a number
(
"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 strip the prefix
zfill(8) pads to 8 bits
(
f
" {n:3d} → {bin(n)[2:].zfill(8)}"
)
(
)
2. Parse from a binary string to decimal
(
"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
)
(
f
" {b} → {dec:3d}"
)
(
)
3. Verify: one byte has exactly 256 values
(
"The range of one byte:"
)
(
f
" Minimum: {int('00000000', 2)}"
)
(
f
" Maximum: {int('11111111', 2)}"
)
(
f
" Total count: {int('11111111', 2) - int('00000000', 2) + 1}"
)
(
)
4. Bit operations: bitwise AND, OR, left shift, right shift
(
"Bit operation examples:"
)
a
=
0b0011
3
b
=
0b0101
5
(
f
" {bin(a)} & {bin(b)} = {bin(a & b)} (bitwise AND)"
)
(
f
" {bin(a)} | {bin(b)} = {bin(a | b)} (bitwise OR)"
)
(
f
" {bin(a)} << 1 = {bin(a << 1)} (left shift by 1 bit, equivalent to multiplying by 2)"
)
(
f
" {bin(b)} >> 1 = {bin(b >> 1)} (right shift by 1 bit, equivalent to dividing by 2)"
)
(
)
5. RUNOOB test string
text
=
"RUNOOB"
(
f
"Binary representation of each character in the string '{text}':"
)
for
ch
in
text:
ascii_val
=
ord
(
ch
)
(
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 0 and 1.
In the following lectures you will see:
- Lecture 2: how to convert between different number systems
- Lecture 3: how negative numbers are represented in binary (two's complement)
- Lecture 4: how fractions are represented in binary (floating point)
- Lecture 5: how text is represented in binary (character encoding)
All of this is built on the foundation that 'everything is 0 and 1'.
The core conclusion of all 5 lectures in this module: the computer has not 'understood' information; rather, through ingenious encoding rules, it maps everything in the world into combinations of 0 and 1.