Number Base Converter
Convert between binary, octal, decimal, hexadecimal and any base from 2 to 36.
Binary is base 2, octal base 8, decimal base 10 and hexadecimal base 16. Decimal 255 is 11111111 in binary, 377 in octal and FF in hexadecimal.
By Piero Nanni · Last checked
Number Base Converter
Binary
—
Octal
—
Decimal
—
Hexadecimal
—
A base is how many digits a system has before it carries. Decimal has ten, so after 9 it carries to 10. Binary has two, so after 1 it carries to 10, which means two. The digits themselves are just labels for place values that are powers of the base: in binary the places are 1, 2, 4, 8, 16; in hexadecimal they are 1, 16, 256, 4096.
Hexadecimal exists because sixteen is two to the fourth, so each hex digit is exactly four binary digits with no remainder. That makes hex a compact way of writing binary that a person can read: 11111111 becomes FF, and a 32-bit value fits in eight characters. Octal plays the same role for three bits at a time, which is why Unix file permissions are octal.
Counting in four bases
| 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 |
Values worth recognising
| Decimal | Binary | Hexadecimal | Where it appears |
|---|---|---|---|
| 15 | 1111 | F | One hex digit, four bits |
| 16 | 10000 | 10 | One byte per hex pair begins |
| 64 | 1000000 | 40 | ASCII @, the mark before A |
| 127 | 1111111 | 7F | Highest 7-bit ASCII code |
| 128 | 10000000 | 80 | Sign bit of a signed byte |
| 255 | 11111111 | FF | Largest unsigned byte |
| 256 | 100000000 | 100 | One more than a byte holds |
| 1024 | 10000000000 | 400 | One kibibyte |
| 4095 | 111111111111 | FFF | Largest 12-bit value |
| 65535 | 1111111111111111 | FFFF | Largest unsigned 16-bit value |
Converting by hand
To go from any base to decimal, multiply each digit by the base raised to its position, counting from zero on the right, and add them. Hex 2F is 2 × 16 + 15 = 47. Binary 1011 is 8 + 0 + 2 + 1 = 11.
To go from decimal to any base, divide repeatedly by the base and read the remainders bottom to top. 47 ÷ 16 is 2 remainder 15, and 2 ÷ 16 is 0 remainder 2, so the digits are 2 and 15, which is 2F.
Binary to hex without arithmetic
Group the binary digits into fours from the right, padding the leftmost group with zeros, and replace each group with its hex digit. 110101111 becomes 0001 1010 1111, which is 1AF. The reverse works the same way: expand each hex digit into four bits.
Octal groups by three instead. That is why a Unix permission of 755 reads as 111 101 101: read, write and execute for the owner, read and execute for everyone else. Each octal digit is exactly one three-bit permission set.
Prefixes and how to read them
Most languages mark the base with a prefix: 0b for binary, 0o or a leading 0 for octal, 0x for hexadecimal. A bare number is decimal. The leading-zero octal convention in C is a well-known source of bugs, since 010 is eight, not ten.
Hexadecimal is case-insensitive: FF and ff are the same value. CSS colours use the same notation, so #FF8000 is three bytes, 255 red, 128 green and 0 blue, which is why hex colour codes are six characters long.
Frequently Asked Questions
What is 255 in binary?
255 in decimal is 11111111 in binary, which is eight ones, the largest value a byte holds.
What is FF in decimal?
Hexadecimal FF is 255 in decimal: 15 × 16 + 15.
Why do computers use hexadecimal?
Sixteen is two to the fourth, so one hex digit is exactly four binary digits. It is a compact, exact shorthand for binary.
How do I convert binary to hex?
Group the bits in fours from the right and replace each group with its hex digit. 1010 1111 is AF.
What base is 0x used for?
0x marks a hexadecimal number, base 16. 0b marks binary and 0o marks octal.