Number Base Converter (Binary, Octal, Decimal, Hex)

Enter a decimal number and pick a target base, or switch direction to read digits written in base 2 to 10. The steps table shows the long-hand working.

Up to 15 digits in all; a fractional part is allowed.
Type the digits as written in that base, e.g. 101101.101 for binary. Only bases up to 10 can be typed into a number field.
Where to stop a fraction that does not terminate in the target base.

Result

101101.101

In words

45.625 (base 10) = 101101.101 (base 2).

Binary (base 2)

101101.101

Octal (base 8)

55.5

Decimal (base 10)

45.625

Hexadecimal (base 16)

2D.A

How it works

A number base, or radix, is how many distinct digits a positional system uses. Decimal uses ten (0–9), binary two (0 and 1), octal eight and hexadecimal sixteen (0–9 then A–F). The same quantity is written differently in each: forty-five is 45 in decimal, 101101 in binary, 55 in octal and 2D in hex. Each digit position is worth a power of the base, so 101101 in binary means 32 + 8 + 4 + 1.

To convert the whole-number part of a decimal number into another base, divide it by the base and keep the remainder, then divide the quotient again, and repeat until the quotient is zero. The remainders, read from the last to the first, are the digits of the result. For 45 into binary: 45 ÷ 2 = 22 r 1, 22 ÷ 2 = 11 r 0, 11 ÷ 2 = 5 r 1, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1, giving 101101.

The fractional part works in the opposite direction: multiply it by the base, take the whole-number part as the next digit, and keep multiplying what is left. For 0.625 into binary: 0.625 × 2 = 1.25 (digit 1), 0.25 × 2 = 0.5 (digit 0), 0.5 × 2 = 1.0 (digit 1), giving .101. Many fractions that terminate in decimal never terminate in binary, so the calculator stops after the number of fraction digits you choose and marks the cut with an ellipsis.

Going the other way, digits written in another base are turned back into decimal by adding up each digit times its place value: 101101.101 in binary is 32 + 8 + 4 + 1 + 0.5 + 0.125 = 45.625. The calculator does all of this in exact integer arithmetic, so the digits shown are the true expansion, not a floating-point approximation.

Formula

whole part:  repeat  q = ⌊n ÷ b⌋,  digit = n mod b,  n = q   until q = 0;  read the digits last to first
fraction:    repeat  f = f × b,  digit = ⌊f⌋,  f = f − ⌊f⌋   until f = 0 or the digit limit is reached
from base b: value = Σ dᵢ × bⁱ   (i counts down from the leftmost whole digit; negative for fraction digits)

Example

45.625 in binary: the whole part 45 divides down as 45, 22, 11, 5, 2, 1, 0 with remainders 1, 0, 1, 1, 0, 1, so 45 = 101101. The fraction 0.625 multiplies up as 1.25, 0.5, 1.0 with whole parts 1, 0, 1, so 0.625 = .101. Together, 45.625 = 101101.101 in base 2, which is 55.5 in octal and 2D.A in hexadecimal.

255 is 11111111 in binary, 377 in octal and FF in hexadecimal. 0.1 in decimal has no finite binary form: 0.0001100110011… repeating, shown as 0.00011001… when cut off after 8 digits.

Reading 101101.101 from base 2 back into decimal: 1 × 2⁵ + 0 × 2⁴ + 1 × 2³ + 1 × 2² + 0 × 2¹ + 1 × 2⁰ + 1 × 2⁻¹ + 0 × 2⁻² + 1 × 2⁻³ = 32 + 8 + 4 + 1 + 0.5 + 0.125 = 45.625.

Assumptions and limitations

  • Digits above 9 are the letters A to Z (A = 10, B = 11, … Z = 35), so base 36 uses all ten digits and all twenty-six letters.
  • The number you enter must have at most 15 digits in all (whole and fractional parts together), with no exponent. The form passes the number as a double-precision value, and 15 significant decimal digits is the most that survives that exactly.
  • Reading digits from another base works only for bases 2 to 10, because a number field cannot accept the letters A–F that bases above 10 need. Hexadecimal input is therefore not supported in this direction; convert the hex digits by hand using the positional sum in the formula.
  • Fractions that do not terminate in the target base are cut off, not rounded, after the number of fraction digits you choose, and the cut is marked with an ellipsis (…). Each of the four standard-base outputs uses the same digit limit.
  • All arithmetic is exact. The conversion steps are the long-hand method and reproduce exactly what the table shows.

Frequently asked questions

Why does 0.1 not convert exactly to binary?

A fraction terminates in a base only if its denominator's prime factors all divide the base. 0.1 is 1 ÷ 10, and 10 = 2 × 5; binary has only the factor 2, so the 5 can never be cleared and the digits repeat forever: 0.000110011001100… This is why computers, which store numbers in binary, cannot hold 0.1 exactly, and why 0.1 + 0.2 is not quite 0.3 in floating point.

How do I convert a hexadecimal number like 2D.A back to decimal?

Use the positional sum: each digit times 16 to the power of its position. 2D.A is 2 × 16 + 13 × 1 + 10 ÷ 16 = 32 + 13 + 0.625 = 45.625. The calculator cannot take letters in its number field, so for bases above 10 do this sum by hand, or first write the hex digits in binary (each hex digit is four bits) and read the binary with the base-2 option.