Number Base Converter
Convert numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, with the digit breakdown that shows how the value is built.
Changing base changes which fractions are exact
Converting a whole number between bases loses nothing — 255 and FF are the same number written twice. Fractions are a different matter. Whether 1/q can be written with finitely many digits depends on the base you write it in, and the rule is exact: 1/q terminates in base b if and only if every prime factor of q also divides b. Nothing about the size of q matters, only which primes are in it.
That rule is easy to state and easy to doubt, so it is worth checking against the thing it predicts. Expanding 1/2 through 1/60 digit by digit in nine different bases and asking whether the digits ever stop gives 531 cases; the prime-factor rule agrees with the actual expansion on every one of them.
| Base | Prime factors | Of 1/2 … 1/100, how many are exact |
|---|---|---|
| 2 | 2 | 6 |
| 3 | 3 | 4 |
| 4 | 2 | 6 |
| 5 | 5 | 2 |
| 6 | 2 · 3 | 19 |
| 8 | 2 | 6 |
| 10 | 2 · 5 | 14 |
| 12 | 2 · 3 | 19 |
| 16 | 2 | 6 |
| 20 | 2 · 5 | 14 |
| 30 | 2 · 3 · 5 | 33 |
| 60 | 2 · 3 · 5 | 33 |
Two things fall out of that table. The first is that a prime base is the worst possible choice: base two can only write powers of two exactly, so of the ninety-nine fractions 1/2 through 1/100 it manages 6. Base ten manages 14, because it has two primes to work with rather than one. The second is that only the distinct primes count — base four behaves exactly like base two and base twenty exactly like base ten, because squaring a base adds no new primes to divide out.
This is the whole of the duodecimal argument in one line. Twelve is 2 · 2 · 3, so it handles thirds and quarters and sixths, and it writes 19 of those ninety-nine exactly against ten's 14. Sixty, which is 2 · 2 · 3 · 5, reaches 33 — which is a reasonable guess at why an hour still has sixty minutes four thousand years after somebody picked the number.
Which is why 0.1 + 0.2 is not 0.3
Ten has the prime factor 5. Two does not. So by the rule above, a tenth cannot be written
exactly in binary — and a computer storing numbers in binary cannot store 0.1. The expansion
is 0.000110011001100110011001… — a leading zero and then
0011 forever, in the same way a third repeats 3 forever in
decimal. Neither is a flaw in the number; both are a mismatch between the number and the base.
What a double-precision float actually holds when you write 0.1 is the nearest
value it can represent, which is
0.1000000000000000055511151231257827 — slightly too big.
Add the similarly-inexact 0.2 and the errors do not cancel, so the sum misses 0.3 by a few
parts in 1017 and 0.1 + 0.2 === 0.3 is false in every language that
uses these floats, which is nearly all of them.
The useful corollary is that the fix is never more precision. Adding digits to a repeating expansion gets you closer and never gets you there. If a value has to be exact — money, most obviously — the answer is to change the representation rather than the precision: store cents as integers, or use a decimal type that carries the base with it. That is the same move as writing 1/3 rather than 0.333, and for the same reason.
How to use
- Enter a number and select its base.
- Read the value in every other base at once.
- Check the place-value breakdown to see the arithmetic.
- Watch for digits that are invalid in the base you selected.
Frequently asked questions
Why does computing use hexadecimal?
Because it maps cleanly onto binary. One hex digit is exactly four bits, so a byte is always two hex digits — no arithmetic needed to convert between them. Decimal has no such relationship with binary, which makes hex the convenient shorthand for anything bit-oriented.
How do I convert decimal to binary by hand?
Divide by two repeatedly and record the remainders, then read them bottom to top. 13 gives remainders 1, 0, 1, 1, which read upward is 1101. The same method works for any base by dividing by that base instead.
What do the letters mean in hexadecimal?
They are digits with values above nine: A is 10, B is 11, through to F for 15. Base 36 continues the pattern all the way to Z for 35, which is why 36 is the practical upper limit for a base using digits and Latin letters alone.
Why is octal still around?
Mostly through Unix file permissions, where each digit neatly encodes three permission bits — which is why chmod uses numbers like 755. Octal was more widely used on early machines with word sizes divisible by three, and hexadecimal displaced it once 8-bit bytes became standard.
What are the common prefixes?
0x means hexadecimal, 0b means binary, and a leading 0 traditionally means octal in C-derived languages — a notorious trap, since a zip code or zero-padded number written as 0755 in source code is not the value it looks like. Newer languages use 0o for octal to avoid exactly this.
How high can a byte count?
255 in decimal, FF in hex, 11111111 in binary — eight bits giving 256 distinct values counting from zero. This is why so many limits in computing are 255 or 256, and why colour channels run 0 to 255.
🔒 This tool runs entirely in your browser. Nothing you enter is uploaded, logged, or stored.