Computer Science

Binary, decimal & hex

A number is just a number, but there’s more than one way to write it down. We use one system every day, computers use another, and a third exists purely to keep humans sane in between. Meet decimal, binary and hexadecimal — the same values, three ways.

Decimal, and why computers can’t use it

We count in base 10 — ten digits, 0 to 9 — probably because we have ten fingers. Computers count in base 2 because their fingers are electrical: a wire carrying voltage (on = 1) or not (off = 0). Two clean states are easy to build, easy to tell apart, and hard to get wrong. Everything else is a matter of stringing enough switches together.

Binary: counting with switches

In base 10, each place is a power of ten: units, tens, hundreds. In binary, each place is a power of two: 1, 2, 4, 8, 16, 32… To read a binary number, add up the place-values wherever there’s a 1:

  • 1 = 1
  • 10 = 2
  • 101 = 4 + 1 = 5
  • 1101 = 8 + 4 + 1 = 13

Turning letters into numbers

If computers only understand numbers, how do they store text? By agreeing on a code. In ASCII, every character has a number — “A” is 65, “a” is 97, a space is 32 — and that number is stored in binary. Type something below and watch it become the 1s and 0s a computer actually holds.

Each character becomes 8 bits (one byte). Hover a byte to see the character and its number.

Hexadecimal: a shorthand for humans

Binary is how computers hold data, but it’s miserable for people to read — a single byte looks like 10110101, easy to miscount and mistype. Hexadecimal, base 16, squeezes those bits into far fewer symbols. It uses sixteen digits: 0–9 as usual, then a, b, c, d, e, f for ten to fifteen. Because sixteen is exactly 2×2×2×2, one hex digit stands for precisely four bits — so a whole clumsy byte collapses into just two neat hex characters. 10110101 becomes simply b5.

See them side by side

Watch the same value in all three systems at once, and set your own range. Notice how binary sprawls while decimal and hex stay short — and how the gap explodes at big numbers. That length difference is the whole reason hex exists.

Decimal 0
Binary 0
Hex 0

Why it matters: bandwidth and storage

That extra length isn’t just cosmetic. Everything a computer stores or sends is ultimately bits, and the number of bits is exactly what fills up disks and clogs networks. How compactly you encode information decides how much storage and bandwidth it costs.

Hex makes the trade-off concrete. A Bitcoin hash is 32 bytes of raw data. Written out as hex for a human to read, it becomes 64 characters — twice the size, because each byte turns into two text symbols. So a computer stores and transmits the raw 32 bytes and only converts to hex when a person actually needs to look at it. In a system like Bitcoin, where every node on Earth stores and relays every transaction, shaving bytes off how data is encoded is a serious, constant concern — it’s part of what keeps the ledger small enough that ordinary people, not just data centres, can run it.

Hex changes nothing about the data itself — it’s the same bits, the same number, just written in a form a person can scan without going cross-eyed. Whenever you see a long string of digits and the letters a–f in Bitcoin — a block hash, a transaction ID, a raw key — you’re simply looking at binary wearing a more comfortable outfit.

Decimal for people, binary for machines, hex as the bridge between them. Next, we bundle those bits into the chunks computers actually move around — bits and bytes.

Key takeaways

  • Computers store everything in binary (base 2) — strings of 1s and 0s, each a switch that’s on or off.
  • Hexadecimal (base 16, 0–f) is a compact human shorthand: one hex digit = 4 bits, so a byte is just two hex characters.
  • Binary needs far more digits than decimal or hex, which matters for storage and bandwidth.

Check yourself

Why do computers use binary (base 2)?

How many bits does one hexadecimal digit represent?

Spotted an error or have feedback on this lesson? Suggest a correction ↗

Comments

Powered by Nostr — reply from any Nostr client, and zap the lesson over Lightning.