Worked example: 2024 in binary and hex
To go from decimal to another base, divide by the base repeatedly and read the remainders from the bottom up. Going from binary to hex is quicker: group the bits in fours from the right and swap each group for one hex digit.
2024 in decimal is 11111101000 in binary
Decimal to binary: divide by 2 and keep the remainders
Divide by 2 until the quotient is 0. The remainders, read from the bottom up, are the binary digits.
| Number | Division | Quotient | Remainder |
|---|---|---|---|
| 2,024 | 2,024 ÷ 2 | 1,012 | 0 |
| 1,012 | 1,012 ÷ 2 | 506 | 0 |
| 506 | 506 ÷ 2 | 253 | 0 |
| 253 | 253 ÷ 2 | 126 | 1 |
| 126 | 126 ÷ 2 | 63 | 0 |
| 63 | 63 ÷ 2 | 31 | 1 |
| 31 | 31 ÷ 2 | 15 | 1 |
| 15 | 15 ÷ 2 | 7 | 1 |
| 7 | 7 ÷ 2 | 3 | 1 |
| 3 | 3 ÷ 2 | 1 | 1 |
| 1 | 1 ÷ 2 | 0 | 1 |
Reading the remainders from bottom to top gives 11111101000
11111101000 in binary is 7E8 in hex
Binary to hex: group the bits in 4s
Because 16 = 2⁴, every 4 bits make exactly one hex digit. Start from the right and pad the leftmost group with zeros if needed.
| 4-bit group | Value | Hex digit |
|---|---|---|
| 0111 | 7 | 7 |
| 1110 | 14 | E |
| 1000 | 8 | 8 |
0111 1110 1000 → 7E8
Binary, decimal, hex and octal table
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 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 | 8 | 10 |
| 9 | 1001 | 9 | 11 |
| 10 | 1010 | A | 12 |
| 11 | 1011 | B | 13 |
| 12 | 1100 | C | 14 |
| 13 | 1101 | D | 15 |
| 14 | 1110 | E | 16 |
| 15 | 1111 | F | 17 |
| 16 | 10000 | 10 | 20 |
| 32 | 100000 | 20 | 40 |
| 64 | 1000000 | 40 | 100 |
| 100 | 1100100 | 64 | 144 |
| 127 | 1111111 | 7F | 177 |
| 128 | 10000000 | 80 | 200 |
| 255 | 11111111 | FF | 377 |
| 256 | 100000000 | 100 | 400 |
| 1000 | 1111101000 | 3E8 | 1750 |
| 1024 | 10000000000 | 400 | 2000 |
| 4096 | 1000000000000 | 1000 | 10000 |
| 65535 | 1111111111111111 | FFFF | 177777 |
Where you need to convert between bases
- Colour codes: the hex colour #FF8000 is red 255, green 128 and blue 0 in decimal.
- Unix file permissions, which are octal: 755 is 111 101 101 in binary, read, write and execute for the owner and read and execute for everyone else.
- Debugging: memory addresses, error codes and register values are usually printed in hex and documented in decimal, or the other way round.
- Networking: IPv4 addresses and subnet masks are easier to reason about in binary, and IPv6 addresses are written in hex.
Frequently asked questions
Which number base is which?
Decimal is base 10, the everyday system with digits 0 to 9. Binary is base 2 (0 and 1), octal is base 8 (0 to 7) and hexadecimal, or hex, is base 16 (0 to 9 then A to F for 10 to 15).
Why do programmers use hex instead of binary?
Each hex digit stands for exactly 4 bits, so a byte is always two hex digits. FF is much easier to read and type than 11111111, and converting between the two is a simple lookup.
Can I convert negative numbers?
Yes. A minus sign is kept in every result, so -255 becomes -11111111 in binary and -FF in hex. The converter does not produce two's complement, which depends on how many bits the value is stored in.
Is there a size limit?
No practical limit. The conversion uses arbitrary precision integers, so long values stay exact. The step-by-step working is shown for numbers up to 24 digits.
Does it handle prefixes such as 0x and 0b?
Yes. 0x for hex, 0b for binary and 0o for octal are removed before converting, as are spaces and underscores used to group digits.
Single conversion tools
Each of these pages converts one way and explains that method in more detail. For text, try Text to Binary or Character to ASCII code.