Base Converter: Binary, Octal, Decimal, Hexadecimal and More
Type a number, say which base it is written in, and choose the base to convert to. Works for every base from 2 to 36, handles negatives and fractional digits, and lists the common bases too.
How positional number systems work
In base b, each digit is worth a power of b. The rightmost integer digit is worth b0, the next b1, and so on. The decimal number 345 means 3×102 + 4×101 + 5×100. The binary number 1101 means 1×8 + 1×4 + 0×2 + 1×1 = 13. Digits to the right of the point continue downward: the first is worth b−1, the second b−2.
A base needs exactly b digit symbols. Binary uses 0 and 1, octal 0 to 7, hexadecimal 0 to 9 plus A to F, and base 36 uses every digit and every letter.
The conversion method used here
The tool first converts the input to an exact value, then rewrites it in the target base. For the integer part it divides repeatedly by the target base and collects the remainders from last to first. For 255 in base 2, the remainders run 1, 1, 1, 1, 1, 1, 1, 1, giving 11111111.
For the fractional part it multiplies by the target base and takes the whole-number part of the result as the next digit, repeating on the remainder. Fractions are held as exact ratios of integers, so no rounding error creeps in. Some fractions never terminate in the new base: 0.1 in decimal is 0.0001100110011... in binary, which is why computers store it only approximately. This page stops after 12 fractional digits and tells you when it has cut a fraction short.
Shortcuts between binary, octal and hex
Because 8 = 23 and 16 = 24, these bases map directly to binary. Group binary digits in threes from the point for octal, or in fours for hexadecimal. The binary number 1111 1111 is F F, so FF in hex. Going the other way, replace each hex digit with its four-bit group: A is 1010, 3 is 0011.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
Common mistakes and limits
- Digits that do not exist in the base. The digit 8 cannot appear in an octal number and 2 cannot appear in binary. The tool reports this instead of guessing.
- Confusing the base with the value. The text "10" is two in base 2, eight in base 8, ten in base 10 and sixteen in base 16.
- Prefixes. Programming prefixes such as 0x and 0b are not part of the number, so leave them out and set the base instead.
- Negative numbers. A minus sign is handled as a sign. This is not two's complement, which is a fixed-width storage format used by hardware.
Integers can be very long because the arithmetic uses arbitrary-precision integers, but the input is limited to 200 digits.
Worked example
Convert the binary number 1011.101 to decimal. The integer part is 11 and the fraction .101 is 5/8, so the answer is 11.625.
Inputs
| Number | 1011.101 |
|---|---|
| From base | 2 |
| To base | 10 |
Result
1011.101 in base 2 equals 11.625 in base 10.
| Binary (base 2) | 1011.101 |
|---|---|
| Octal (base 8) | 13.5 |
| Decimal (base 10) | 11.625 |
| Hexadecimal (base 16) | B.A |
- Letters stand for digits above 9: A = 10, B = 11, up to Z = 35.
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
How do I convert binary to decimal by hand?
Write the place values 1, 2, 4, 8 and so on from the right, then add the place values wherever the binary digit is 1. For example, 1101 is 8 + 4 + 1 = 13.
What do the letters mean in hexadecimal?
Hexadecimal needs sixteen symbols, so after 0 to 9 it uses A to F for the values ten to fifteen. This calculator extends the idea to Z for bases up to 36.
Is this the same as two's complement?
No. This converter treats a minus sign as a sign and writes the magnitude in the new base. Two's complement is a fixed-width way of storing negative values in hardware.
Why does a short decimal fraction become long in binary?
A fraction terminates in base b only if its denominator has prime factors found in b. Tenths involve a factor of 5, which binary lacks, so 0.1 repeats forever in binary.
What is the largest base supported?
Base 36, which uses the ten digits and the 26 letters of the Latin alphabet. Bases above that need extra symbols that have no standard form.
Related calculators
References and sources
- Knuth, D. E. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 4.1 on positional number systems.