Computers count in binary — base 2, with only two digits: 0 and 1. Why this restriction, and how does it produce the rich digital world we use? The answer connects physics (transistors), math (binary arithmetic), and the entire architecture of modern computing.
Why binary?
Computers use binary because the underlying hardware (transistors, memory cells) has two stable states: on or off, high voltage or low voltage. Trying to make hardware reliably distinguish between 10 different voltage levels (decimal) would be much harder than distinguishing between just 2 (binary). Hardware reliability scales with simplicity.
So engineering forced binary, and math made it elegant.
How binary counts
In decimal, place values are powers of 10: ones, tens, hundreds, thousands. The number 1234 means 1×1000 + 2×100 + 3×10 + 4×1.
In binary, place values are powers of 2: ones, twos, fours, eights, sixteens. The number 1011 in binary means 1×8 + 0×4 + 1×2 + 1×1 = 11 in decimal.
Each binary digit position has value double the previous: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048...
Counting from 0 to 15
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
4-bit values count from 0 to 15. 8-bit values (a byte) count from 0 to 255.
The pattern
Each new bit doubles the range. Add a leading 1, and you double the count:
- 4 bits: 0–15 (16 values, 2⁴)
- 8 bits: 0–255 (256 values, 2⁸)
- 16 bits: 0–65,535 (2¹⁶)
- 32 bits: 0–4.29 billion (2³²)
- 64 bits: 0–18.4 quintillion (2⁶⁴)
Converting decimal to binary
Method: divide by 2 repeatedly, write down the remainders, read bottom-up.
Convert 13 to binary:
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
- Read bottom up: 1101
Verify: 1×8 + 1×4 + 0×2 + 1×1 = 8+4+0+1 = 13. ✓
Converting binary to decimal
Easier: multiply each bit by its place value, sum.
1 0 1 0 1 1
Place values right-to-left: 1, 2, 4, 8, 16, 32.
1×32 + 0×16 + 1×8 + 0×4 + 1×2 + 1×1 = 32+8+2+1 = 43.
Binary arithmetic
Addition rules:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (the 0 stays, carry 1)
- 1 + 1 + 1 (with carry) = 11 (1 stays, carry 1)
Add 1011 + 0110 (= 11 + 6 = 17):
1011 + 0110 ------ 10001
10001 in binary = 1×16 + 0×8 + 0×4 + 0×2 + 1×1 = 17. ✓
Why bits matter for software
Each integer in a computer has a fixed bit count:
- byte (8 bits): small numbers 0–255, raw data, ASCII characters.
- short (16 bits): small game sprites, audio samples.
- int (32 bits): standard size for most numeric variables.
- long (64 bits): bigger numbers, timestamps, memory addresses.
Going beyond a bit-width means the number wraps around to 0 (or causes errors). 8-bit + 1 = 0 (overflow). This caused the Pac-Man kill screen at level 256 — the level counter was a single byte and rolled over.
Why binary is also clever
- Simple multiplication: binary multiplication uses just shifts and additions. No memorization tables.
- Boolean logic: 1 = true, 0 = false. AND, OR, NOT operations work the same on bits as on logic statements.
- Easy storage: any state can be encoded as bits. ASCII characters, colors, audio, video — all binary.
- Reliable transmission: noise can flip a single bit; error correction can detect or fix it.
Beyond integers: how binary handles fractions
Decimal fractions: 0.5 = 5/10. Binary fractions: 0.1 = 1/2 = 0.5 decimal.
Binary place values for fractions: 0.5, 0.25, 0.125, 0.0625, etc. (powers of 1/2).
Some decimal fractions don't have clean binary representations: 0.1 decimal is an infinitely repeating binary number. This is why floating-point math has rounding errors — 0.1 + 0.2 ≠ 0.3 in JavaScript and many languages.
The bigger picture
Everything in a computer is bits: text, images, sound, video, code. The interpretation depends on context. The same 64-bit value could be:
- An integer (64-bit signed: −9.2 quintillion to +9.2 quintillion)
- A double (64-bit floating point)
- 8 ASCII characters
- A pointer to a memory address
- Half of an IPv6 address
The bits themselves are neutral. The program decides the interpretation.
Practice conversions
Our binary, decimal, hex converter handles all conversions instantly. Useful for verifying your manual conversions while learning, or for quick checks during programming.