Number Base Converter
Convert whole numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36, with exact results for long values.
What is a number base converter?
A positional numeral system writes a number as a sequence of digits, each multiplied by a power of the base (or radix). Decimal uses base 10, binary base 2, octal base 8 and hexadecimal base 16. This converter reads a whole number written in any base from 2 to 36 and writes the same value in binary, octal, decimal, hexadecimal and a chosen target base. Values are held as exact integers, so long inputs are converted without rounding.
How to use this converter
- Type the number, then enter the base it is written in. Hexadecimal input such as FF needs input base 16.
- Enter a target base for the highlighted result. The four common bases are always shown underneath.
- Results update as you type. A message explains any digit that does not belong to the input base.
Digits above 9 are written with letters: A is 10, B is 11 and so on up to Z for 35, which is why 36 is the largest base supported. Output letters are shown in upper case. The status line also reports how many bits the value needs in binary.
The formula
For digits dn−1 … d1 d0 in base b, the value is dn−1 × bn−1 + … + d1 × b + d0. The converter evaluates this from left to right as value = value × b + digit (Horner's method). To write the value in a target base, it is divided repeatedly by that base; the remainders, read from last to first, are the new digits.
Worked example
Decimal 255 divided by 16 is 15 remainder 15, and 15 divided by 16 is 0 remainder 15. Both remainders are the digit F, so 255 is FF in hexadecimal. In binary, 255 = 28 − 1, which is 11111111, and in octal it is 3 × 64 + 7 × 8 + 7 = 377. In base 36 it is 7 × 36 + 3 = 73.
Signs, fractions and input limits
Negative numbers are converted as a minus sign followed by the magnitude, for example −10 is −1010 in binary. This is not the two's complement form a computer uses for fixed-width signed integers, which depends on the word size. Zero converts to 0 in every base, and −0 is shown as 0.
Only whole numbers are supported: a decimal point, comma, space or any character outside the input base's digits produces a message instead of a result. Leading zeros are allowed and ignored. A 0b, 0o or 0x prefix is removed only when it matches the input base, because in base 36, for instance, B and X are ordinary digits. Inputs are limited to 64 digits and bases to the range 2–36. Exact arithmetic uses the browser's built-in BigInt support; no library or remote service is needed.