Binary, Decimal, and Hex: Converting Number Bases
Decimal has ten digits because people have ten fingers. Everything else about number bases follows the same pattern with a different count. The Number Base Converter handles binary, octal, decimal and hexadecimal.
How any base works
In decimal, each column is ten times the one to its right: units, tens, hundreds. In binary each column is twice the one to its right: 1, 2, 4, 8, 16. In hexadecimal each is sixteen times: 1, 16, 256, 4096.
So reading a number is the same operation in any base - multiply each digit by its column value and add. Binary 1011 is 8 plus 0 plus 2 plus 1, which is 11.
Hex needs six extra digits beyond 0 to 9, and uses A to F for ten to fifteen. So hex F is 15, hex 10 is sixteen, and hex FF is 255 - the number that turns up everywhere because it is the largest value a single byte can hold.
Hex exists to make binary readable
This is the part that makes the whole subject click. Sixteen is two to the fourth, so one hex digit is exactly four binary digits. Always, with no arithmetic.
That means converting between binary and hex is pure substitution. Split the binary into groups of four from the right, and replace each group with its hex digit: 1111 is F, 1010 is A, so 11111010 is FA. No multiplication, no carrying.
Eight bits is a byte, and a byte is exactly two hex digits. Which is why a colour code is six hex digits - two each for red, green and blue - and why the HEX/RGB/HSL Converter is really doing base conversion with a colour wrapped around it.
Octal, base eight, is three bits per digit and exists for the same reason. It was common when machines used 12 and 36-bit words and survives mostly in Unix file permissions, where each digit neatly carries three yes-or-no flags.
Where you will meet each one
Binary in flags, bitmasks and anything close to hardware. Hex in colour codes, memory addresses, MAC addresses, character codes and hashes from the Hash Generator. Octal in file permissions. Decimal everywhere else.
A practical note: hex is often written with a 0x prefix in code and a hash in colours, and both just mean "read this as hex". Without a marker, 10 is ambiguous - it is ten in decimal, two in binary and sixteen in hex.
Common questions
Why is 255 everywhere?
Because eight bits hold 256 values, 0 to 255. One byte per colour channel, one byte per character in older encodings.
What are the powers of two worth knowing?
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024. After that they are familiar as storage sizes.
How do I convert decimal to binary by hand?
Divide by two repeatedly, writing down each remainder, then read the remainders backwards.
Why do computers use binary at all?
Because a circuit reliably distinguishes two states - on and off - and distinguishing ten would need far finer tolerances for no gain.
Got a number to convert?