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.
| Base | Name | Digits | Prefix | Typical use |
|---|---|---|---|---|
| 2 | Binary | 0 1 | 0b | bits, logic, machine data |
| 8 | Octal | 0–7 | 0o (older: leading 0) | Unix file permissions |
| 10 | Decimal | 0–9 | none | everyday numbers |
| 16 | Hexadecimal | 0–9, A–F | 0x | bytes, memory addresses, colors |
| 36 | Base 36 | 0–9, A–Z | none | short 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.
| Decimal | Binary | Octal | Hex | Base 36 |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 | 2 |
| 3 | 11 | 3 | 3 | 3 |
| 4 | 100 | 4 | 4 | 4 |
| 5 | 101 | 5 | 5 | 5 |
| 6 | 110 | 6 | 6 | 6 |
| 7 | 111 | 7 | 7 | 7 |
| 8 | 1000 | 10 | 8 | 8 |
| 9 | 1001 | 11 | 9 | 9 |
| 10 | 1010 | 12 | A | A |
| 11 | 1011 | 13 | B | B |
| 12 | 1100 | 14 | C | C |
| 13 | 1101 | 15 | D | D |
| 14 | 1110 | 16 | E | E |
| 15 | 1111 | 17 | F | F |
| 16 | 10000 | 20 | 10 | G |
| 17 | 10001 | 21 | 11 | H |
| 18 | 10010 | 22 | 12 | I |
| 19 | 10011 | 23 | 13 | J |
| 20 | 10100 | 24 | 14 | K |
| 21 | 10101 | 25 | 15 | L |
| 22 | 10110 | 26 | 16 | M |
| 23 | 10111 | 27 | 17 | N |
| 24 | 11000 | 30 | 18 | O |
| 25 | 11001 | 31 | 19 | P |
| 26 | 11010 | 32 | 1A | Q |
| 27 | 11011 | 33 | 1B | R |
| 28 | 11100 | 34 | 1C | S |
| 29 | 11101 | 35 | 1D | T |
| 30 | 11110 | 36 | 1E | U |
| 31 | 11111 | 37 | 1F | V |
| 32 | 100000 | 40 | 20 | W |
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³⁰.
| Power | Decimal | Hex | Binary prefix |
|---|---|---|---|
| 2⁰ | 1 | 1 | |
| 2¹ | 2 | 2 | |
| 2² | 4 | 4 | |
| 2³ | 8 | 8 | |
| 2⁴ | 16 | 10 | |
| 2⁷ | 128 | 80 | |
| 2⁸ | 256 | 100 | |
| 2¹⁰ | 1,024 | 400 | 1 Ki (kibi) |
| 2¹⁶ | 65,536 | 10000 | |
| 2²⁰ | 1,048,576 | 100000 | 1 Mi (mebi) |
| 2³⁰ | 1,073,741,824 | 40000000 | 1 Gi (gibi) |
| 2³² | 4,294,967,296 | 100000000 |
Sources: NIST: Prefixes for binary multiples