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:
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
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
Two's Complement Calculator
Signed integers in two's complement, one's complement and sign-magnitude, plus overflow.
OpenIEEE 754 Floating-Point Converter
32 and 64-bit floating point with biased exponent and rounding error.
OpenKarnaugh Map Solver
Minimal SOP and POS expressions with the groups highlighted on the map.
OpenIPv4 Subnet Calculator
Network, broadcast, hosts, wildcard and VLSM planning with the binary AND.
OpenTruth Table Generator
Truth table for any expression, with minterms and canonical forms.
OpenSorting Algorithm Visualizer
Animated sorting with comparison and write counters.
Open