How base conversion works
Each position in a number is worth the base raised to a power. In binary, 1011 = 1×8 + 0×4 + 1×2 + 1×1 = 11. In hexadecimal, digits go 0–9 then A–F, so FF = 15×16 + 15 = 255.
The rightmost digit is worth base0 = 1, the next base1, then base2, and so on. Octal 755 is 7×64 + 5×8 + 5×1 = 493. Bases above 10 borrow letters, which is why base 36 is the highest: 0–9 plus A–Z gives 36 digits, and ZZ in base 36 is 35×36 + 35 = 1,295.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
| 1024 | 10000000000 | 2000 | 400 |
Worked example: decimal to hex by hand
Divide by the target base repeatedly and read the remainders from last to first. For 3054 in hex:
3054 ÷ 16 = 190 remainder 14 (E)
190 ÷ 16 = 11 remainder 14 (E)
11 ÷ 16 = 0 remainder 11 (B)
read upward: BEE
Type 3054 with Decimal selected and the converter shows hex BEE, binary 101111101110 and octal 5756, and notes that the value needs 12 bits.
Shortcuts between binary, octal and hex
Because 16 = 24 and 8 = 23, each hex digit is exactly four bits and each octal digit exactly three. To convert binary to hex, group bits in fours from the right: 1011 1110 1110 is B, E, E. That is why hex is the usual shorthand for bytes: one byte is always two hex digits, from 00 to FF. Octal survives mainly in Unix file permissions, where 755 is the bits 111 101 101, or rwx r-x r-x.
Negative numbers and two's complement
Computers store signed integers in two's complement: invert every bit of the positive value and add 1. In 8 bits, −1 is 11111111 (0xFF) and −128 is 10000000. The table shows how your number is stored at 8, 16, 32 and 64 bits, and what the same bits mean when read as unsigned.
For example, −42 in 8 bits: 42 is 00101010, inverted it is 11010101, and adding 1 gives 11010110, or 0xD6. Read as unsigned, those same bits are 214. An n-bit signed integer holds −2n−1 to 2n−1 − 1, so an 8-bit value runs from −128 to 127. The table shows Does not fit for widths too small for your number.
The main results show a negative number with a minus sign, as in -101010; only the two's complement table shows the stored bit pattern.
Prefixes 0x, 0b and 0o and separators like 1111_0000 are accepted.
Common mistakes
- Prefix in the wrong base. A prefix is only stripped when it matches It is in;
0x1Fwith Decimal selected is an error, because x is not a decimal digit. - Leading zeros meaning octal. In C, C++ and non-strict JavaScript,
010is octal and equals 8. Strict-mode JavaScript and Python 3 reject it; Python and needs0o10. - Losing precision in JavaScript. Plain numbers are exact only up to 253 = 9,007,199,254,740,992.
parseInt("9007199254740993")returns ...992. This page uses BigInt, so large values stay exact; use BigInt in your own code too. - Mixing up signed and unsigned.
DEADBEEFis 3,735,928,559 as an unsigned 32-bit value but −559,038,737 as signed. Check which one the API or file format expects.
Edge cases
Only whole numbers are supported; a decimal point is reported as an invalid digit. Letters are case-insensitive on input and shown in uppercase. Values wider than 64 bits convert exactly between bases, but the two's complement table shows Does not fit for every width.