Hex and binary converter
Decimal, hex, binary and octal, all four at once
Type in any box. The example turns 255 into hex, binary and octal.
–
- Bits needed
- –
- Bytes needed
- –
- Two's complement
- –
How the converter works
Decimal, hex, binary and octal are four ways of writing the same whole number. Decimal uses ten digits (base 10). Hex, short for hexadecimal, uses sixteen: 0 to 9, then A to F for 10 to 15. Binary uses only 0 and 1 (base 2), and octal uses 0 to 7 (base 8). Type in any box and the other three fill in. The numbers are kept as exact whole numbers, so even a 1,000-digit number is converted without rounding.
Worked example
255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15. Each 15 is the hex digit F, so 255 is FF. Going back, FF = 15 × 16 + 15 = 255. In binary, F is 1111, so FF is 1111 1111, which is one byte. The working line under the answer shows these steps for your number.
What you can type
Spaces and underscores between digits are ignored. The prefixes 0x (hex), # (colour codes), 0b (binary) and 0o (octal) are accepted. Letters can be capitals or lower case. A digit that does not belong, such as G in hex or 2 in binary, gets a message naming it.
Negative numbers
A minus sign is kept in front: -255 is -FF in hex. Computers usually store negative numbers as two's complement in a fixed number of bits, where -1 is FF in 8 bits. The page shows that separately, so the main answers stay plain. Fractions and decimal points are not converted.
Decimal, hex, binary and octal chart
The numbers 0 to 16 and some common round values.
| Decimal | Hex | Binary | Octal |
|---|---|---|---|
| 0 | 0 | 0000 | 0 |
| 1 | 1 | 0001 | 1 |
| 2 | 2 | 0010 | 2 |
| 3 | 3 | 0011 | 3 |
| 4 | 4 | 0100 | 4 |
| 5 | 5 | 0101 | 5 |
| 6 | 6 | 0110 | 6 |
| 7 | 7 | 0111 | 7 |
| 8 | 8 | 1000 | 10 |
| 9 | 9 | 1001 | 11 |
| 10 | A | 1010 | 12 |
| 11 | B | 1011 | 13 |
| 12 | C | 1100 | 14 |
| 13 | D | 1101 | 15 |
| 14 | E | 1110 | 16 |
| 15 | F | 1111 | 17 |
| 16 | 10 | 10000 | 20 |
| 32 | 20 | 10 0000 | 40 |
| 64 | 40 | 100 0000 | 100 |
| 100 | 64 | 110 0100 | 144 |
| 127 | 7F | 111 1111 | 177 |
| 128 | 80 | 1000 0000 | 200 |
| 255 | FF | 1111 1111 | 377 |
| 256 | 100 | 1 0000 0000 | 400 |
| 1,000 | 3E8 | 11 1110 1000 | 1750 |
| 1,024 | 400 | 100 0000 0000 | 2000 |
| 4,096 | 1000 | 1 0000 0000 0000 | 10000 |
| 65,535 | FFFF | 1111 1111 1111 1111 | 177777 |
Rules and sources
- Place value: in base b, each digit is multiplied by b raised to its position, counting from 0 at the right, and the results are added. Hex digits A to F stand for 10 to 15.
- Decimal to another base: divide by the base again and again; the remainders, read from the last to the first, are the digits.
- Hex and binary line up: each hex digit is exactly four binary digits, and each octal digit three.
- Exact for any size: the page uses the browser's BigInt whole numbers (ECMAScript language specification, BigInt type), so nothing is rounded, even for numbers far past 253.
- Negative numbers: shown with a minus sign in front (signed magnitude, -FF). Two's complement, which is how computers store negatives in a fixed number of bits, is shown separately for 8, 16, 32, 64 or 128 bits: the value is 2bits minus the size of the number.
Found a mistake?
Email [email protected] with the page, what you typed and what you expected. Confirmed errors are fixed and added to the check.