How to Convert Number Bases: Binary, Hex and Beyond
Last updated: · 4 min read
Computers store data in binary (0 and 1), programmers read it in hexadecimal (0 to F), and everyday life runs on decimal. Knowing how one value is written in another base matters for colour codes, memory addresses, file permissions and network masks. This guide explains the rule of positional notation and shows, step by step, how a number moves between bases. The results in the example are the real output of the Number Base Converter tool.
Formula
Input base to decimal (Horner's method): v = 0 for each digit d from left to right: v = v × base + d Decimal to any other base: 1. d = n mod base (the digit) 2. n = ⌊n ÷ base⌋ 3. repeat until n = 0; write the digits from last to first Digit values: 0–9 → 0–9; A–Z (case does not matter) → 10–35
This follows from the definition of positional notation: the value of a digit is the digit multiplied by the base raised to its position. Horner's method computes that sum with one multiplication and one addition per digit. The tool uses BigInt, so very large numbers are exact. Negative inputs such as -FF keep their sign, and the prefixes 0b, 0o and 0x are accepted for their own bases.
What the inputs mean
- Number
- The number to convert, written with digits valid in the chosen input base, for example FF in base 16 or 11111111 in base 2. Spaces and underscores are ignored.
- Input base
- The base the number is written in: 2, 8, 10, 16 or Custom base. The largest digit must be smaller than the base.
- Custom base
- A whole number from 2 to 36. In base 36 only the digits 0–9 and A–Z are used.
Worked example: Converting FF to other bases
- Input: FF, input base 16. Horner's method: F = 15, so v = 0 × 16 + 15 = 15, then v = 15 × 16 + 15 = 255.
- Decimal 255 to binary: 255 mod 2 = 1, ⌊255 ÷ 2⌋ = 127, and so on for eight steps, giving 11111111: Binary (2): 11111111.
- To octal: 255 = 3×64 + 7×8 + 7, so the output is Octal (8): 377.
- Back to hexadecimal gives FF again: Hexadecimal (16): FF.
- In base 32, 255 = 7×32 + 31 and the digit 31 is written V, giving Base 32: 7V. In base 36, 255 = 7×36 + 3, so Base 36: 73.
Result: Tool output: Binary (2): 11111111, Octal (8): 377, Decimal (10): 255, Hexadecimal (16): FF, Base 32: 7V, Base 36: 73.
How to read the result
A number written without a prefix is only meaningful with its base: 10 is ten in decimal but sixteen in hexadecimal. In code, the prefixes 0b, 0o and 0x make the base explicit. For negative values, computers usually store two's complement; this tool shows the sign with the magnitude and does not produce a two's complement representation.
Common mistakes
- Choosing the wrong input base. “100” is one hundred in decimal, four in binary and 256 in hexadecimal.
- Using a digit that is too large for the base. The digit 2, 7 or F is invalid in base 2, and the tool reports an error.
- Confusing letter case or prefixes with digits. a–f and A–F have the same value, but the 0x or 0b prefix is not a digit.
- Computing large numbers with the ordinary JavaScript Number type. Whole numbers above 2^53 cannot be stored exactly, which is why the tool uses BigInt.
- Trying to convert a fraction. The tool converts whole numbers only; a value such as 0.5 is not accepted.
Frequently asked questions
Why are bases above 36 not offered?
The usual digit symbols are 0–9 and A–Z, which give 36 digits. A larger base would need extra symbols, and there is no widely accepted convention for them.
Why do hexadecimal numbers contain letters?
Base 16 needs 16 digits: 0–9 and A (10) to F (15). One byte is written exactly with two hexadecimal digits.
Does the converter keep the minus sign?
Yes. An input of -FF gives a result with the minus sign. Two's complement, the way computers store negative numbers in memory, is a separate topic.
Does a very large number convert correctly?
Yes. The tool uses BigInt, so large whole numbers are exact; up to 5000 digits are accepted.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.