How it works
In our normal decimal system each place is worth ten times the place to its right: ones, tens, hundreds. A different base just changes that multiplier. In binary (base 2) the places are 1, 2, 4, 8, 16 and so on, and only the digits 0 and 1 are used, which is exactly what computer circuits store as off and on.
Hexadecimal (base 16) uses 0-9 and then A-F for ten to fifteen. Each hex digit stands for exactly four binary digits, which is why programmers use hex as a compact way to write binary, for example in colour codes like #FF8800.
Formula
- To decimal: multiply each digit by base^position and add
- From decimal: divide by the base repeatedly; the remainders, read bottom to top, are the digits
- 1 hex digit = 4 bits; 2 hex digits = 1 byte
Solved example
202 in binary: 202 = 128 + 64 + 8 + 2, so the binary is 1100 1010. In hex that is CA (1100 = C, 1010 = A).
Binary 1011 = 8 + 0 + 2 + 1 = 11. Hex FF = 15 x 16 + 15 = 255, the largest value one byte can hold.
FAQ
Why do computers use binary?
Electronic switches are reliably either on or off. Two states map perfectly to the digits 1 and 0.
What are bits and bytes?
A bit is one binary digit. A byte is 8 bits, enough for 256 different values (0 to 255).
Can it handle very big numbers?
Yes, up to 40 digits, using exact whole-number arithmetic so nothing is rounded.