Number Base Converter
Convert whole numbers between binary, octal, decimal and hexadecimal, or any base from 2 to 36. Results are exact, even for numbers with hundreds of digits.
Convert a number between bases
Result
- Binary
- —
- Octal
- —
- Decimal
- —
- Hexadecimal
- —
Popular base conversions
The four common bases
| Base | Radix | Digits | Code prefix | Bits per digit |
|---|---|---|---|---|
| Binary | 2 | 0 and 1 | 0b | 1 |
| Octal | 8 | 0 to 7 | 0o | 3 |
| Decimal | 10 | 0 to 9 | none | not a power of two |
| Hexadecimal | 16 | 0 to 9 and A to F | 0x | 4 |
Binary. Binary is base 2: it has only the digits 0 and 1, and each place is worth twice the place to its right (1, 2, 4, 8, 16, …). In code, binary literals are written with the prefix 0b, as in 0b1010. Computers store and process everything as binary digits (bits). Eight bits make one byte.
Octal. Octal is base 8: it uses the digits 0 to 7 and each place is worth eight times the place to its right. One octal digit stands for exactly three bits. In many languages an octal literal is written 0o17 (older C code writes a leading zero, 017). Octal is best known from Unix file permissions: chmod 755 is three octal digits, one for owner, group and others.
Decimal. Decimal is base 10: the digits 0 to 9, and each place is worth ten times the place to its right. It is the system people write by default, so it is the one every other base is usually converted to or from. Decimal is the everyday number system for counting, money and measurement.
Hexadecimal. Hexadecimal is base 16: the digits 0 to 9 followed by the letters A to F for ten to fifteen. One hex digit stands for exactly four bits, so two hex digits make one byte. In code a hex literal is written with the prefix 0x, as in 0xFF. Hexadecimal writes bytes compactly: web colors (#FF8800), memory addresses, MAC addresses and character codes all use it.
Numbers 0 to 16 in each base
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 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 |
| 16 | 10000 | 20 | 10 |
How to convert between number bases
To decimal. Multiply each digit by the base raised to the power of its position, counting from 0 at the right, and add the results. In binary, 1011 is 1 × 8 + 0 × 4 + 1 × 2 + 1 × 1 = 11.
From decimal. Divide the number by the target base, write down the remainder and repeat with the quotient until it reaches 0. The remainders, read from last to first, are the digits. For 11 in binary: 11 ÷ 2 = 5 remainder 1, 5 ÷ 2 = 2 remainder 1, 2 ÷ 2 = 1 remainder 0, 1 ÷ 2 = 0 remainder 1, which reads 1011.
Between binary, octal and hexadecimal. All three are powers of two, so no arithmetic is needed. Group the bits in threes for octal or fours for hexadecimal, starting from the right, and replace each group with its digit.
Frequently asked questions
- How do I convert a number from one base to another?
- To convert to decimal, multiply each digit by the base raised to its position and add the results. To convert from decimal, divide repeatedly by the target base and read the remainders from last to first. Binary, octal and hexadecimal convert to each other directly by regrouping bits.
- Does the converter handle negative numbers and very large numbers?
- Yes. A leading minus sign is kept, and numbers of up to 2000 digits convert exactly because the calculation uses arbitrary-size integers. Negative values are shown with a minus sign, not as two's complement.
- Can I convert numbers with a decimal point, such as 0.5 in binary?
- Not here. This converter handles whole numbers only. Fractions need a different method because many decimal fractions, such as 0.1, repeat forever in binary.
- What do the prefixes 0b, 0o and 0x mean?
- They tell a programming language which base a literal is written in: 0b for binary, 0o for octal and 0x for hexadecimal. The converter accepts them in the input, so 0xFF and FF both work in hexadecimal.
- Which bases can I use besides binary, octal, decimal and hexadecimal?
- Any base from 2 to 36. Digits above 9 are written with the letters A to Z, so base 36 uses all ten digits and all twenty-six letters.