Number Base Converter
Number Base Converter
Need a full color palette?Color Palette Generator
Binary, octal, decimal and hexadecimal
Every one of these is the same number written with a different number of available digits. Decimal has ten, so each column is worth ten times the one to its right. Binary has two, hexadecimal has sixteen. The number itself does not change; only the notation does.
Hexadecimal earns its place because 16 is 2⁴, so exactly four binary digits fit in one hex digit with nothing left over. That makes hex a compact, lossless shorthand for binary: a byte is always exactly two hex digits, which is why memory dumps, colour codes and hashes are all written in hex rather than binary or decimal.
Worked examples
| Decimal | Other bases |
|---|---|
| 255 | binary 11111111 · octal 377 · hex FFThe largest value in one byte. |
| 10 | binary 1010 · octal 12 · hex A |
| 64 | binary 1000000 · octal 100 · hex 40A power of two is a 1 followed by zeros in binary. |
| 4095 | binary 111111111111 · octal 7777 · hex FFFTwelve bits, so three hex digits. |
| 65535 | binary 1111111111111111 · octal 177777 · hex FFFFThe largest 16-bit value. |
Bit widths
| Bits | Maximum unsigned value | Hex digits |
|---|---|---|
| 4 | 15 | 1 |
| 8 | 255 | 2 |
| 16 | 65,535 | 4 |
| 32 | 4,294,967,295 | 8 |
| 64 | 18,446,744,073,709,551,615 | 16 |
Worth knowing
- Prefixes signal the base in most languages:
0bfor binary,0oor a leading0for octal,0xfor hexadecimal. - One hex digit is exactly 4 bits (a nibble). One byte is exactly 2 hex digits. One octal digit is exactly 3 bits, which is why octal suits Unix permissions: three permission bits per digit.
- The largest value in n bits is 2ⁿ − 1. Eight bits reach 255, sixteen reach 65,535, thirty-two reach 4,294,967,295.
- Hex digits past 9 use letters A–F for 10–15. They are case-insensitive.
Frequently asked questions
- Why do programmers use hexadecimal instead of binary?
- Because one hex digit maps to exactly four binary digits, so hex is a lossless shorthand that is four times shorter. A 32-bit value takes 32 characters in binary and 8 in hex, and you can convert either way in your head one digit at a time. Decimal has no such alignment with binary.
- What does the 0x prefix mean?
- It marks the number that follows as hexadecimal. Most languages inherited the convention from C. Similarly 0b marks binary and 0o marks octal. A bare leading zero means octal in C, Java and older JavaScript, which is a well-known source of bugs in code that pads numbers with zeros.
- What is the largest number you can store in 8 bits?
- 255 if unsigned, because the maximum in n bits is 2 to the power n minus 1. If the value is signed, one bit encodes the sign and the range becomes −128 to 127.
- Why is octal still used for Unix file permissions?
- Because one octal digit is exactly three bits, and Unix permissions come in groups of three: read, write and execute. That makes each digit of a mode like 755 a complete permission set for one class of user, with no bit spanning two digits.