Number Systems and Conversions

2.Why Numbers Have Letters in Them

A

In this chapter

We'll learn to count like a computer: the decimal, binary, octal and hexadecimal number systems, how to convert between them by hand, and why computers use binary in the first place.

14–16 min

The Problem in Real Life

John opens Zoë's name in a tool called a hex viewer, which shows the raw bytes of a file. Instead of letters, Anna sees this: 5A 6F C3 AB.

"Four bytes," John says. "Z, o, and two bytes for the ë. But to understand why the ë broke, you need to be able to read these numbers." Anna stares at the screen. Since when do numbers have letters in them?

A

C3? AB? I thought numbers only went up to 9.

Anna

Counting in Tens vs. Counting in Twos

Numbers with letters

Hexadecimal uses A–F as digits, which looks strange until you see why.

Same number, different ways to write it

Thirteen can be written 13, 1101 or D — it's the same amount, written in different number systems.

Number Systems and How to Convert Between Them

John asks a strange question: "Why do we count in tens?" Anna shrugs. "Because... we have ten fingers?" "Exactly. It's not special. It's just the system we picked."

A number system is a way of writing amounts using a fixed set of digits. The number of digits it uses is called its base. When you run out of digits, you carry over to the next column — the same way 9 + 1 becomes 10.

  • Decimal (base 10) — digits 0 to 9. What people use every day. Each column is worth 10 times the one on its right: ones, tens, hundreds. So 347 = 3 hundreds + 4 tens + 7 ones.
  • Binary (base 2) — digits 0 and 1 only. What computers use. Each column is worth 2 times the one on its right: 1, 2, 4, 8, 16, 32, 64, 128...
  • Octal (base 8) — digits 0 to 7. Not used much today, but you'll meet it in Linux file permissions like 755 (Act 06).
  • Hexadecimal (base 16), or hex — digits 0 to 9, then A, B, C, D, E, F for ten to fifteen. Programmers love hex because one hex digit is exactly 4 bits, so one byte (8 bits) is always exactly two hex digits. C3 is just a short way to write the byte 11000011.
Table — The same numbers in four systems
DecimalBinaryOctalHex
0000000
5010155
91001119
10101012A
13110115D
15111117F
161 00002010
2551111 1111377FF
This whole line is a row — one record

255 is the biggest value one byte can hold: eight 1s in binary, FF in hex.

Table — Reading a binary number: 1101
Column value8421
Bit1101
Counts?84—1

Add the columns that have a 1: 8 + 4 + 1 = 13.

Table — Where you'll see hex in real life
PlaceExampleWhat it means
Web colours#FF0000Red 255, green 0, blue 0 — pure red
Raw file bytesC3 ABTwo bytes of a file, shown in a hex viewer
Network hardware3C:22:FB:9A:10:7EA MAC address (Act 11)
Error codes0x80070005A Windows error number ("0x" means hex)

Why do computers use binary at all? Because inside a chip, everything is electricity, and the easiest thing to build reliably is a switch with two states: current flowing (1) or not flowing (0). A tiny electronic switch called a transistor does this, and a modern CPU has billions of them. Trying to tell ten different voltage levels apart would be far more error-prone than telling just two apart. Two states is simple, cheap and very reliable.

Binary → decimal. Write the column values over the bits and add up the columns that have a 1. For 1101: the columns are 8, 4, 2, 1. So 8 + 4 + 0 + 1 = 13.

Decimal → binary. Keep dividing by 2 and write down the remainders, then read them from bottom to top. 13 ÷ 2 = 6 remainder 1; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. Read upwards: 1101.

Binary → hex. Split the bits into groups of four from the right, and turn each group into one hex digit. 1100 0011 → 1100 is 12, which is C; 0011 is 3. So 11000011 = C3.

Hex → binary. Do the opposite: turn each hex digit into four bits. AB → A is 10 = 1010, B is 11 = 1011. So AB = 10101011.

Now Anna can read the hex viewer: 5A 6F C3 AB is four bytes. She doesn't yet know which letters they stand for — that's the chapter after next — but they're no longer a mystery. They're just numbers, written in a short form.

Key Takeaway

Decimal, binary, octal and hex are just different ways to write the same amounts. Computers use binary because a switch with two states is simple and reliable; programmers use hex because one hex digit is exactly four bits, so every byte fits in two hex digits.

Why This Matters

You won't convert numbers by hand every day at work. But you will constantly see binary and hex: in colour codes, error messages, memory addresses, network addresses and debugging tools. Being able to read them calmly — instead of panicking at "0x80070005" — is a real everyday skill, and it's exactly what lets Anna solve Zoë's bug two chapters from now.

Anna can now read bytes. Before she gets to Zoë's name, John shows her something that surprises almost every new programmer: numbers themselves can go wrong inside a computer — and on a ticketing site, those numbers are prices.

Next