Back to Number Base Converter

Theoretical Background: Number Base Converter

Open the app

Positional number systems

In base \(b\), a number with digits \(d_i\) (each \(0 \le d_i < b\)) has the value

$$ (d_n \dots d_1 d_0 . d_{-1} d_{-2} \dots)_b = \sum_{i} d_i \, b^{\,i} $$

Each place is worth \(b\) times the place to its right. Base 10 uses digits 0–9; base 2 uses 0 and 1; base 16 uses 0–9 and A–F (A = 10 … F = 15); base 36 uses all of 0–9 and A–Z.

Step 1 – to decimal

Multiply each digit by its place value and add:

$$ 11111111.101_2 = 2^7+2^6+\dots+2^0 + 2^{-1} + 2^{-3} = 255 + 0.5 + 0.125 = 255.625_{10} $$

Step 2 – from decimal to base b

Whole part: divide by \(b\) repeatedly; the remainders, read from the last to the first, are the digits.

Fractional part: multiply by \(b\) repeatedly; the whole parts, read from the first to the last, are the digits.

Worked example

Example

Convert 255.625₁₀ to binary.

DivisionQuotientRemainder
255 ÷ 21271
127 ÷ 2631
63 ÷ 2311
31 ÷ 2151
15 ÷ 271
7 ÷ 231
3 ÷ 211
1 ÷ 201

Whole part: 11111111. Fraction: 0.625 × 2 = 1.25 → 0.25 × 2 = 0.5 → 0.5 × 2 = 1.0 → .101.

Result: \(255.625_{10} = 11111111.101_2 = 377.5_8 = \mathrm{FF.A}_{16}\).

Shortcuts between 2, 8 and 16

Because \(8 = 2^3\) and \(16 = 2^4\), each octal digit is exactly three bits and each hexadecimal digit exactly four bits. Group the bits from the point outwards:

$$ 1111\,1111.1010_2 = \mathrm{F}\,\mathrm{F}.\mathrm{A}_{16}, \qquad 011\,111\,111.101_2 = 377.5_8 $$

Where bases are used

  • Binary – how computers store numbers and logic levels.
  • Hexadecimal – memory addresses, colour codes (#1B3A6B), byte values.
  • Octal – Unix file permissions (chmod 755).
  • Base 12 and 60 – dozens, hours and minutes, angles.
  • Base 36 – short IDs and URL codes using all letters and digits.

FAQ

Why does 0.1 not convert exactly to binary?

A fraction terminates in base b only if its denominator has no prime factors other than those of b. 1/10 has the factor 5, which 2 lacks, so its binary form repeats forever.

How large can the numbers be?

Whole parts are converted with exact big-integer arithmetic, so there is no practical size limit. Fractional parts are given to 20 digits.

Can I type lower-case hex?

Yes. ff, Ff and FF are the same number.

What is the largest base?

Base 36, because there are 10 digits and 26 letters to write the digit values 0–35.