Number systems: binary, octal, decimal and hex
A number system is a way of writing numbers with a fixed set of digits. Computing uses four: binary, octal, decimal and hexadecimal. Convert any number between them in the box, then compare them below.
Prefixes 0b, 0o, 0x and spaces or underscores between digits are fine. A point starts the fraction.
The four number systems
| System | Base | Digits | Place values | 255 written in it | Prefix in code |
|---|---|---|---|---|---|
| Binary | 2 | 0 1 | 1, 2, 4, 8, 16 … | 11111111 | 0b |
| Octal | 8 | 0 to 7 | 1, 8, 64, 512 … | 377 | 0o |
| Decimal | 10 | 0 to 9 | 1, 10, 100, 1000 … | 255 | none |
| Hexadecimal | 16 | 0 to 9, A to F | 1, 16, 256, 4096 … | FF | 0x |
The prefixes are the ones JavaScript uses (ECMA-262, section 12.9.3); many other languages use the same ones.
0 to 16 in all four systems
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
Place values: the idea behind every base
In any number system, each place is worth the base times the place to its right.
In decimal, 352 is 3 hundreds, 5 tens and 2 ones. In hexadecimal, 352 means 3 × 256 + 5 × 16 + 2 = 850. The digits are the same; the base changes what they are worth. That is why it helps to write the base as a small subscript, 35216, or to use a prefix such as 0x.
How to convert between number systems
| From → to | Method | Converter |
|---|---|---|
| Any base → decimal | Multiply each digit by its place value and add | binary, octal, hex |
| Decimal → any base | Divide by the base repeatedly; read the remainders from the bottom up | binary, octal, hex |
| Binary ↔ hex | Group bits in fours; each group is one hex digit | binary to hex, hex to binary |
| Binary ↔ octal | Group bits in threes; each group is one octal digit | binary to octal, octal to binary |
| Octal ↔ hex | Go through binary: three bits per octal digit, then regroup in fours | base converter |
Why does computing use four number systems?
Computers store everything in binary, because their circuits work with two states. People think in decimal.
Hexadecimal and octal sit in between: 16 and 8 are powers of 2, so each hex digit is exactly four bits and each octal digit exactly three. That makes them short, exact ways of writing binary. Hex is the common choice today, because a byte is exactly two hex digits; octal survives in places such as Unix file permissions.
Sources and method
- ECMA-262, ECMAScript Language Specification, section 12.9.3 Numeric Literals: the 0b, 0o and 0x prefixes for binary, octal and hex. Checked 2026-11-25.
Conversions use exact whole-number arithmetic (JavaScript BigInt), so long numbers keep every digit. Fractions are kept as exact ratios; when the digits repeat, the repeating block is found and marked instead of rounded.
Questions
What are the four number systems?
Binary (base 2), octal (base 8), decimal (base 10) and hexadecimal (base 16).
Which number system do computers use?
Binary. Octal and hexadecimal are shorthand that people use to read and write binary more easily.
What is a number system converter?
A tool that rewrites a number from one base into another, such as decimal to binary. The box on this page converts between any bases from 2 to 36.
Why is 10 not always ten?
Because “10” means one of the base and nothing more. In binary 10 is two, in octal it is eight and in hex it is sixteen.