Computers represent numbers in binary, and we write them in decimal. Programmers also work with hexadecimal and octal every day. This guide explains what each base is, how to convert between them by hand, and when to use the base converter on this site to check your results.
What is a number base
The base of a number system indicates how many distinct symbols it uses to represent numbers:
- Decimal (base 10): ours. Ten symbols: 0-9.
- Binary (base 2): computers'. Two symbols: 0 and 1.
- Octal (base 8): eight symbols: 0-7.
- Hexadecimal (base 16): sixteen symbols: 0-9 and A-F (where A=10, B=11... F=15).
In any base, each position is worth the base raised to its position, starting at 0 on the right. In decimal, 345 = 3×100 + 4×10 + 5×1. Binary works the same way, but with powers of 2.
Why computing uses binary
Digital circuits distinguish two states, on (1) or off (0). That's why all information (numbers, text, images) is represented internally in binary. A single binary digit is a bit; eight bits are a byte.
Why programmers use hexadecimal
Binary is hard to read: 11111111 is eight digits to represent 255. Hexadecimal is much more compact because each hex digit equals exactly 4 bits. So 11111111 in binary is FF in hexadecimal. That's why you'll see hex in:
- CSS colors:
#FF5733. - Memory addresses and dumps.
- Error codes and registers.
- MAC addresses and UUIDs.
In the color #FF5733, each pair of digits is one channel: FF is 255 of red, 57 is 87 of green and 33 is 51 of blue. For more on how colors are written, see hex, RGB and HSL colors.
How to convert between bases
Decimal to binary
Divide by 2 repeatedly and note the remainders. With 13: 13 ÷ 2 = 6 remainder 1; 6 ÷ 2 = 3 remainder 0; 3 ÷ 2 = 1 remainder 1; 1 ÷ 2 = 0 remainder 1. Reading the remainders bottom-up gives 1101.
Binary to decimal
Add the powers of 2 at the positions with 1. 1101 = 8 + 4 + 0 + 1 = 13.
Binary to hexadecimal
Group the binary into blocks of 4 bits and convert each block. 1101 0011 → D3.
Hexadecimal to decimal
Multiply each digit by 16 raised to its position. D3 = 13×16 + 3 = 211.
Doing it by hand is easy to get wrong. The base converter does the conversion instantly and accepts the 0b, 0o and 0x prefixes when you type.
Quick examples
| Decimal | Binary | Hexadecimal | Octal |
|---|---|---|---|
| 8 | 1000 | 8 | 10 |
| 15 | 1111 | F | 17 |
| 16 | 10000 | 10 | 20 |
| 255 | 11111111 | FF | 377 |
| 256 | 100000000 | 100 | 400 |
Frequently asked questions
Why is 255 such a common number? It's the largest value that fits in an unsigned byte (8 bits): 11111111. That's why RGB color channels go from 0 to 255.
What is 0x in programming? The 0x prefix indicates a number is in hexadecimal: 0xFF = 255. The 0b prefix indicates binary.
What is octal used for today? Less than before. It's seen mostly in Unix file permissions, such as chmod 755, where each octal digit groups three permission bits. We cover it in Linux permissions in octal and symbolic notation.
Is my data uploaded when converting? No. The converter does the math with JavaScript in your browser and doesn't send the number to any server.
Convert between binary, decimal, hexadecimal and octal instantly with the free base converter, 100% in your browser.