Place value is the whole idea
In decimal, each place is worth 10 times the one to its right: 255 = 2×100 + 5×10 + 5×1. Binary works the same way with 2: each place is worth 1, 2, 4, 8, 16 and so on, and the only digits are 0 and 1. Hexadecimal uses 16, with digits 0–9 and then A–F for 10–15.
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Binary to decimal
Add up the place values that have a 1. 1101 = 8 + 4 + 0 + 1 = 13. 11111111 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255.
Decimal to binary
Divide by 2 again and again, writing down the remainders, then read them from the bottom up. For 13: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1. Reading upward gives 1101.
Binary to hex, and back
This is why programmers love hex: every hex digit is exactly four binary digits. Split the binary into groups of four from the right and swap each group using the table. 1111 1111 = FF. 0010 1010 = 2A, which is 42 in decimal. To go back, write each hex digit as four bits: 3C = 0011 1100.
Negative numbers: two's complement
Computers usually store negative whole numbers in two's complement. To get −x in 8 bits, flip every bit of x and add 1. 5 is 0000 0101; flipped it's 1111 1010; add 1 and −5 is 1111 1011 (FB in hex). The top bit tells you the sign, so 8 bits hold −128 to 127 signed, or 0 to 255 unsigned. When a sum goes past the end it wraps around: in 8-bit signed, 127 + 1 = −128.
Try it
The programmer calculator converts between all four bases at once, shows every bit, does AND, OR, XOR, NOT and shifts, and lets you pick 8, 16, 32 or 64 bits, signed or unsigned.
Every worked example on this page was checked with Calcist's own engine and an independent reference.