Number bases: how to convert binary, octal and hexadecimal
Learn how to convert between decimal, binary, octal and hexadecimal, understand place value, and see why hex appears in colors, memory and permissions.
255, FF and 11111111 represent the same number — only the base changes. Anyone working with programming, electronics or interface design runs into all three forms constantly, and mixing them up is a classic source of error: a color that should be white turns black, a file permission changes behavior.
This guide explains what a number base is, how to convert to decimal and back, the shortcuts between binary, octal and hexadecimal, and where each system shows up in daily work. To convert right now, use the number base converter.
What is a number base?
The base is the number of digits available in a numeral system. Decimal (base 10) uses 0 to 9. Binary (base 2) uses only 0 and 1. Octal (base 8) uses 0 to 7. Hexadecimal (base 16) uses 0 to 9 plus the letters A to F, which stand for 10 to 15.
Each digit's value depends on its position: in decimal, 352 means 3 × 100 + 5 × 10 + 2 × 1. The same logic applies to any base — only the number raised to the position changes.
How to convert to decimal
Add each digit multiplied by the base raised to its position, starting from zero on the right:
value = digit × baseposition
Examples:
- Binary 1101: 1 × 8 + 1 × 4 + 0 × 2 + 1 × 1 = 13.
- Hexadecimal FF: 15 × 16 + 15 × 1 = 255.
- Octal 52: 5 × 8 + 2 × 1 = 42.
How to convert from decimal to another base
The reverse path is repeated division: divide the number by the base, keep the remainder, and repeat with the quotient until it reaches zero. The result is formed by the remainders read from bottom to top.
To convert 42 to binary: 42 ÷ 2 = 21, remainder 0; 21 ÷ 2 = 10, remainder 1; 10 ÷ 2 = 5, remainder 0; 5 ÷ 2 = 2, remainder 1; 2 ÷ 2 = 1, remainder 0; 1 ÷ 2 = 0, remainder 1. Reading bottom to top: 101010.
The same 42 in octal is 52 (42 ÷ 8 = 5, remainder 2; 5 ÷ 8 = 0, remainder 5) and in hexadecimal it is 2A (42 ÷ 16 = 2, remainder 10 = A; 2 ÷ 16 = 0, remainder 2).
Shortcuts between binary, octal and hexadecimal
Because 8 and 16 are powers of 2, converting between these systems is simpler than it looks:
- Octal: each octal digit corresponds to exactly 3 bits. 7 becomes 111; 5 becomes 101.
- Hexadecimal: each hexadecimal digit corresponds to 4 bits. F becomes 1111; A becomes 1010.
That is why 1111 1111 in binary is FF in hexadecimal and 255 in decimal. And the Unix permission 755 becomes 111 101 101 in binary — each digit represents a combination of read, write and execute.
Where this shows up in daily work
- Colors:
#FF0000is pure red; each hexadecimal pair represents a channel from 0 to 255. - Memory and debugging: addresses and bytes appear in hexadecimal because each digit covers 4 bits.
- File permissions:
chmod 755uses octal to combine owner, group and other permissions. - Bit masks: flags and settings are often written in binary or hexadecimal.
Common mistakes when converting bases
- Invalid digit: 2 does not exist in binary; 8 does not exist in octal; G does not exist in hexadecimal.
- Confusing the number with the base: “10” in binary is 2 in decimal, not 10.
- Reading remainders in the wrong order: in repeated division, the first remainder is the least significant digit.
- Treating A and a as different values: in hexadecimal, both mean 10.
- Losing precision: very large numbers can lose accuracy in integer math.
Convert without doing the math
In the number base converter, type the number, choose the input base and see the equivalent in decimal, binary, octal and hexadecimal at the same time. Validation warns you when a digit does not belong to the selected base — handy for quickly checking a color, a permission or a debugging value.