Binary, octal, decimal and hexadecimal
All four are positional number systems. They work the same way as the decimal numbers you already know, only with a different number of digits. In decimal (base 10) each position is worth ten times the one to its right. In binary (base 2) each position is worth twice as much, in octal (base 8) eight times, and in hexadecimal (base 16) sixteen times. Hexadecimal needs six extra digits, so it uses the letters A to F for the values 10 to 15.
This converter updates all four bases as you type in any one of them. It uses arbitrary-precision integers, so very large values such as 128-bit IDs or cryptographic keys convert exactly. You can paste values with prefixes like 0x, 0b or 0o, and spaces or underscores between digits are ignored.
How to convert hex to decimal
Multiply each hex digit by 16 raised to the power of its position, counting from 0 on the right, then add the results. For 2AF:
- 2 × 16² = 2 × 256 = 512
- A (10) × 16¹ = 10 × 16 = 160
- F (15) × 16⁰ = 15 × 1 = 15
512 + 160 + 15 = 687. The same method works for any base: for binary, use powers of 2, and for octal, powers of 8.
How to convert decimal to hex
Divide by 16 repeatedly and write down the remainders. Reading the remainders from last to first gives the hex number. For 687: 687 ÷ 16 = 42 remainder 15 (F), 42 ÷ 16 = 2 remainder 10 (A), 2 ÷ 16 = 0 remainder 2. Reading upward gives 2AF. Dividing by 2 or 8 instead gives binary or octal.
Why hex and binary fit together
Sixteen is 2⁴, so every hex digit stands for exactly four bits, a group called a nibble. That makes converting between hex and binary a simple lookup rather than arithmetic: replace each hex digit with its four bits, or split the binary into groups of four from the right. Two hex digits make one byte, which is why hex is the standard way to show raw bytes. The bit view above labels each nibble with its hex digit.
| Hex | Binary | Decimal | Hex | Binary | Decimal |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
Where you will see each base
- Hexadecimal: memory addresses, color codes such as
#FF8800, MAC addresses, Unicode code points (U+00E9), error codes, hashes and hex dumps of files. - Binary: bit flags, masks and registers in embedded code, and subnet masks in networking (255.255.255.0 is 24 ones followed by 8 zeros).
- Octal: mainly Unix file permissions. In
chmod 755each digit is three bits: read (4), write (2) and execute (1), for the owner, group and everyone else.
Negative numbers and two's complement
Computers usually store negative integers in two's complement: invert all the bits of the positive value and add one. In 8 bits, 42 is 00101010, so −42 is 11010110, or 0xD6. The same bit pattern read as an unsigned number is 214. The fields above show negative numbers with a minus sign, and the bit view shows how they are stored at the selected width, along with both the signed and unsigned readings.
Prefixes in code
Most programming languages mark the base with a prefix: 0x for hex, 0b for binary and 0o for octal (Python, JavaScript, Rust). In C and older JavaScript, a plain leading zero means octal, so 010 is 8, not 10, which is a classic source of bugs.