Counting is a convention, not a fact of nature. We use ten symbols because we have ten fingers. Computers have no fingers. They have transistors: tiny switches that are either on or off. Two states. So computers count in base 2 - binary - not because it is elegant but because it is the only natural choice when your elementary unit has exactly two possible values.

Every number your computer stores, every instruction it executes, every pixel it draws - all of it is binary at the lowest level. The abstractions on top are real and useful, but they sit on this foundation.


How Decimal Actually Works

Before binary makes sense, it helps to understand what decimal really means - because most people use it without thinking about the structure beneath it.

In decimal we have ten symbols: 0 through 9. When we exhaust them, we do not invent new ones - we add a new position. Each position carries a weight: a power of 10.

The number $347$ means:

$$3 \times 10^2 + 4 \times 10^1 + 7 \times 10^0 = 300 + 40 + 7$$

The rightmost position has weight $10^0 = 1$. Each position to the left is ten times heavier. The base (10) determines both the number of symbols available and the multiplier between adjacent positions.


Binary: The Same Structure, Base 2

Binary uses only two symbols: 0 and 1. Each position carries a weight that is a power of 2.

The binary number $1011$ means:

1 0 1 1 2⁰ 8 0 2 1 8 + 0 + 2 + 1 = 11 in decimal

The rightmost bit is called the least significant bit (LSB); the leftmost is the most significant bit (MSB). Each bit either contributes its power of 2 or does not.

Powers of 2 worth knowing: $1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024$. An 8-bit number can represent $2^8 = 256$ distinct values (0 through 255). A 32-bit number can represent over 4 billion.


Binary to Decimal

Read the bits left to right. Multiply each by its positional weight and sum.

Example. Convert $10110100$ to decimal.

Bit $2^7$ $2^6$ $2^5$ $2^4$ $2^3$ $2^2$ $2^1$ $2^0$
Value 1 0 1 1 0 1 0 0
Weight 128 64 32 16 8 4 2 1
Contribution 128 0 32 16 0 4 0 0

$128 + 32 + 16 + 4 = 180$.


Decimal to Binary

Method: repeated division by 2. Divide the number by 2 repeatedly; the remainders, read bottom to top, give the binary representation.

Example. Convert 42 to binary.

Division Quotient Remainder
$42 \div 2$ 21 0
$21 \div 2$ 10 1
$10 \div 2$ 5 0
$5 \div 2$ 2 1
$2 \div 2$ 1 0
$1 \div 2$ 0 1

Reading remainders bottom to top: $101010$. Check: $32 + 8 + 2 = 42$. ✓

Why does this work? Each division by 2 strips off the least significant bit (the remainder is that bit). You are peeling the binary representation one bit at a time from the right. Reading the remainders bottom to top reverses that order, recovering the binary number left to right.


Hexadecimal: Binary’s Shorthand

Binary is unwieldy to write by hand. The number 255 is $11111111$ - eight ones. Humans make transcription errors. Hexadecimal (base 16) solves this by grouping binary digits.

Hexadecimal uses 16 symbols: 0-9, then A-F for values 10-15.

Decimal Binary Hex
0 0000 0
5 0101 5
10 1010 A
15 1111 F
16 0001 0000 10
255 1111 1111 FF

The key insight: one hex digit represents exactly 4 binary digits. So any binary number can be converted to hex by grouping bits in fours from the right.

Example. Convert $10110100$ to hex.

Split into groups of 4: $1011\ 0100$. Each group: $1011 = 11 = \text{B}$, $0100 = 4$. So $10110100 = \text{0xB4}$.

The prefix $\text{0x}$ is the conventional notation for hexadecimal. Memory addresses, color codes ($\text{#FF5733}$), and byte values in debuggers are all displayed in hex.

Why base 16 and not base 8? Both work - base 8 (octal) groups bits in threes. But modern computers work in multiples of 8 bits (bytes), and $8 = 2 \times 4$: two hex digits represent exactly one byte. Hex became the standard because it maps perfectly onto the byte boundary that modern hardware cares about.


Why Computers Use Binary

You might wonder: why not base 10, since that is what humans use? The answer is physical. A transistor is reliable at two states - fully on or fully off. Trying to distinguish ten voltage levels (0.0V, 0.5V, 1.0V, …, 4.5V) in a real circuit with noise, temperature variation, and manufacturing tolerances is extremely difficult to do reliably at billions of operations per second.

Two states is simple, robust, and fast. Every other numerical system a computer appears to support - decimal displays, floating-point arithmetic, hexadecimal notation - is built on top of this binary foundation.


Summary

System Base Symbols Position weight
Decimal 10 0-9 Powers of 10
Binary 2 0, 1 Powers of 2
Hexadecimal 16 0-9, A-F Powers of 16
  • 1 bit = one binary digit (0 or 1)
  • 1 byte = 8 bits, range 0-255 ($2^8 - 1$)
  • 1 nibble = 4 bits = 1 hex digit
  • $n$ bits represent $2^n$ distinct values

Read next: