Computer science

Number Base Converter

Enter a number in any base from 2 to 36 and see it in the other bases, with the working your exam asks for.

Fractional parts (with a point) and prefixes 0x, 0b are accepted. Examples:

How positional number systems work

In a positional system with base b, each digit is worth its symbol multiplied by a power of b that depends on its position. In decimal, 352 is 3·10² + 5·10¹ + 2·10⁰. In binary, 1101 is 1·2³ + 1·2² + 0·2¹ + 1·2⁰ = 13. Bases above 10 use letters: A = 10, B = 11… up to Z = 35 in base 36.

From any base to decimal

Apply the definition: multiply each digit by the base raised to its position and add everything up. To the right of the radix point the positions are negative (b⁻¹, b⁻², …).

Example · 3F2₁₆ to decimal

3·16² + 15·16¹ + 2·16⁰ = 768 + 240 + 2 = 1010.

From decimal to any base

The integer part is converted by repeated division: divide by the base, write down the remainder and repeat with the quotient until it is 0. The number is the list of remainders read from bottom to top. The fractional part is converted by repeated multiplication: multiply by the base, the integer part is the next digit and you continue with the remaining fraction; here the digits are read from top to bottom.

Example · 156.625 to binary

Integer part: 156 → remainders 0, 0, 1, 1, 1, 0, 0, 1 → read backwards, 10011100. Fractional part: 0.625·2 = 1.25 → 1; 0.25·2 = 0.5 → 0; 0.5·2 = 1 → 1. Result: 10011100.101₂.

Shortcut between binary, octal and hexadecimal

Since 8 = 2³ and 16 = 2⁴, each octal digit is exactly 3 bits and each hex digit is exactly 4. There is no need to go through decimal: group the bits from the radix point (padding with zeros on the left of the integer part and on the right of the fraction) and translate each group.

Example · 11010110₂ to hexadecimal

1101 | 0110 → D | 6 → D6₁₆. And to octal: 011 | 010 | 110 → 3 | 2 | 6 → 326₈.

Decimal, binary, octal and hex conversion table

The first 16 values, worth memorizing to convert quickly between binary and hexadecimal:

DecimalBinaryOctalHexadecimal
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Useful powers of 2: 2⁸ = 256 (one byte), 2¹⁰ = 1,024, 2¹⁶ = 65,536 and 2³² = 4,294,967,296.

Frequently asked questions

Why can't 0.1 be represented exactly in binary?

A fraction has a finite expansion in base b only if its reduced denominator contains no prime factors other than those of b. 0.1 = 1/10 and 10 = 2·5: 5 is not a factor of 2, so in binary it repeats forever (0.000110011…). That is why 0.1 + 0.2 is not exactly 0.3 in floating point; see it in the IEEE 754 converter.

How many bits do I need for a decimal number N?

⌊log₂ N⌋ + 1 bits. With n bits you can represent unsigned values from 0 to 2ⁿ − 1. For negative numbers, see the two's complement calculator.

Is there a size limit?

Not in practice: the tool works with arbitrary-precision integers, so you can convert numbers with hundreds of digits without losing accuracy. The fractional part is cut when it does not terminate.

Can I convert hex to binary directly?

Yes. Choose base 16 as the source and base 2 as the target: each hex digit becomes four bits, and the tool shows the grouping shortcut.

More computer science tools