Home › Calculators & Converters › Number Base Converter

Number Base Converter

Convert a whole number between bases 2 and 36. Any size is exact, and you can show the 8, 16, 32 or 64-bit two's complement pattern of a negative number.

Digits 0 to 9 and letters a to z, in any case. One optional minus sign at the start.

Value (signed decimal)-
BaseValue
2 (binary)-
8 (octal)-
10 (decimal)-
16 (hexadecimal)-
36-
Everything runs in your browser. The number you type is not sent or stored.

How it works

Exact arithmetic. The number is read digit by digit into a BigInt, which holds whole numbers of any size with no rounding. Each digit is worth its value times the base raised to its place, so 255 in base 16 is 15 × 16 + 15. The result is written out in each base from the same exact value, so a 40-digit number stays exact in every row.

Digits and prefixes. Letters are case-insensitive and output is lower case. Base 36 uses 0 to 9 and a to z. With the base set to auto, a prefix of 0b, 0o or 0x sets the base, and otherwise the number is read as decimal. A digit that is not below the base is refused, and the message names it.

Two's complement. A computer stores a negative number with a fixed width. At 8 bits the range is −128 to 127. A negative value is shown as its bit pattern by adding two raised to the width (2 to the power of 8 is 256), so −1 at 8 bits is 256 − 1 = 255, which is 11111111 in binary and ff in hex. Binary, octal and hex are padded to the full number of digits for the width (8 bits gives 8 binary digits, 3 octal and 2 hex). Decimal is not padded. A value outside the range for the width is refused.

Grouping. Binary and hex digits can be grouped in fours from the right, separated by a space. Grouping only changes how the digits are laid out, so the value is the same.