Number Bases Explained: Binary, Octal, Decimal, Hex

Published July 26, 2026By Samson PG

Quick answer

A number base is just how many digits you get before you carry — decimal carries at 10, binary at 2, hex at 16. Once that clicks, every binary/hex value stops looking like a secret code.

Number Base Converter

Every number base represents the exact same quantity — they just carry to the next digit at a different point. Decimal (base 10) carries after 9 because it has 10 digits (0-9). Binary (base 2) only has two digits (0, 1), so it carries after every single 1. Hexadecimal (base 16) has sixteen digits (0-9, then A-F for 10-15), so it can go much further before carrying. Same number, different digit budget.

The four you’ll actually see

Base Name Digits used Example: decimal 202
2 Binary 0, 1 11001010
8 Octal 0-7 312
10 Decimal 0-9 202
16 Hexadecimal 0-9, A-F CA

How to actually convert by hand

Each digit’s value is (digit value) × (base ^ position), counting positions from 0 on the right. For binary 11001010:

1×2^7 + 1×2^6 + 0×2^5 + 0×2^4 + 1×2^3 + 0×2^2 + 1×2^1 + 0×2^0
= 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0
= 202

For hex CA: C is 12, A is 10, so 12×16^1 + 10×16^0 = 192 + 10 = 202. Same number as the binary above — just fewer digits needed because base 16 packs more value per digit.

Why hex specifically is everywhere in programming

Hex isn’t arbitrary — it exists because one hex digit exactly represents four binary digits (since 16 = 2⁴). 0xCA and 11001010 are the exact same value, but hex needs 2 characters where binary needs 8. That’s why:

  • Colors are hex (#FF5733) — each pair of digits is exactly one byte (0-255) for red, green, blue.
  • Memory addresses and pointers are shown in hex — a clean, compact stand-in for the actual binary address.
  • Byte dumps, hashes, and MAC addresses are hex — every 2 hex characters = 1 byte, with no rounding or awkward grouping.

Octal is much rarer today but still shows up in one specific place: Unix file permissions (chmod 755), because 3 bits (one octal digit) map cleanly onto one permission triplet (read/write/execute).

The mistake that trips people up: leading zeros and sign

010 in a language that still treats a leading zero as octal means decimal 8, not ten — a classic bug source, which is why most modern languages require an explicit 0o prefix for octal (0o10) and treat a bare leading-zero decimal as either an error or just decimal. Similarly, 0x (hex) and 0b (binary) prefixes exist specifically so a value isn’t ambiguous about which base it’s written in.

FAQ

Why does binary use only 0 and 1?

Because it maps directly onto a physical two-state system (a transistor being on/off, a bit being high/low voltage) — computers don’t have a native “0-9” digit, they have “signal present or not,” which is inherently base 2.

Is there a shortcut between binary and hex without going through decimal?

Yes — split the binary digits into groups of 4 from the right, and convert each group directly to one hex digit (1100 = C, 1010 = A), which is exactly why 11001010 becomes CA with no decimal math needed at all.

What’s the largest value one byte (8 bits) can hold?

11111111 in binary, FF in hex, 377 in octal — all equal to 255 in decimal, since 8 bits gives 2⁸ = 256 possible values, counting from 0.

Does JavaScript’s Number() handle all four bases?

Not uniformly — parseInt(str, radix) with an explicit radix argument is the reliable way to parse any base; relying on prefix-sniffing alone (0x, 0b, 0o) works in modern JS but is easy to get wrong across older code or user input that omits the prefix.

← More from the blog

TryDevSnip