Numeral Systems: Binary, Octal, Decimal and Hexadecimal

Positional number systems write the same value with different bases. This page explains place value, the digits and prefixes used for each common base, and lists 0 to 32 in binary, octal, decimal, hex and base 36.

Place value in any base

In base b, each digit is multiplied by a power of b according to its position: the value of dₙ…d₁d₀ is dₙ·bⁿ + … + d₁·b + d₀. For example, binary 1011 = 1·8 + 0·4 + 1·2 + 1·1 = 11, and hex 2F = 2·16 + 15 = 47.

One hex digit is exactly four bits and one octal digit exactly three bits, which is why programmers use hex and octal as a compact way to write binary.

Common bases with their digits, programming prefixes and uses
BaseNameDigitsPrefixTypical use
2Binary0 10bbits, logic, machine data
8Octal0–70o (older: leading 0)Unix file permissions
10Decimal0–9noneeveryday numbers
16Hexadecimal0–9, A–F0xbytes, memory addresses, colors
36Base 360–9, A–Znoneshort alphanumeric IDs

Sources: Ecma TC39: ECMAScript Language Specification (Number.prototype.toString radix 2–36)

Conversion table, 0 to 32

Every row below is computed by converting the decimal value to each base.

Numbers 0 to 32 in decimal, binary, octal, hexadecimal and base 36
DecimalBinaryOctalHexBase 36
00000
11111
210222
311333
4100444
5101555
6110666
7111777
810001088
910011199
10101012AA
11101113BB
12110014CC
13110115DD
14111016EE
15111117FF
16100002010G
17100012111H
18100102212I
19100112313J
20101002414K
21101012515L
22101102616M
23101112717N
24110003018O
25110013119P
2611010321AQ
2711011331BR
2811100341CS
2911101351DT
3011110361EU
3111111371FV
321000004020W

Powers of 2 and byte sizes

Powers of 2 are round numbers in binary and hex. The SI prefixes kilo, mega and giga mean powers of 10; the IEC binary prefixes kibi (Ki), mebi (Mi) and gibi (Gi) mean 2¹⁰, 2²⁰ and 2³⁰.

Powers of 2 in decimal, hex and binary prefix
PowerDecimalHexBinary prefix
2⁰11
2¹22
2²44
2³88
2⁴1610
2⁷12880
2⁸256100
2¹⁰1,0244001 Ki (kibi)
2¹⁶65,53610000
2²⁰1,048,5761000001 Mi (mebi)
2³⁰1,073,741,824400000001 Gi (gibi)
2³²4,294,967,296100000000

Sources: NIST: Prefixes for binary multiples

References

Frequently asked questions

How do I convert decimal to binary?

Divide by 2 repeatedly and record the remainders; read them from last to first. For 13: 13→6 r1, 6→3 r0, 3→1 r1, 1→0 r1, so 13 = 1101 in binary.

Why does hexadecimal use letters?

Base 16 needs sixteen digit symbols. After 0–9, the letters A–F stand for 10–15, so FF = 15·16 + 15 = 255, the largest value of one byte.