Number Base Converter: How It Works
Every number system works the same way — each position is worth a power of the base. Understanding that one idea makes binary, octal and hexadecimal straightforward, and explains why programmers reach for hex constantly while ordinary arithmetic never needs it.
Positional value
In base 10, 3,742 means 3×10³ + 7×10² + 4×10¹ + 2×10⁰. Every base follows the identical pattern with a different multiplier.
| Base | Name | Digits | Where used |
|---|---|---|---|
| 2 | Binary | 0–1 | All digital hardware; bit flags |
| 8 | Octal | 0–7 | Unix file permissions |
| 10 | Decimal | 0–9 | Everyday arithmetic |
| 16 | Hexadecimal | 0–9, A–F | Colours, memory addresses, hashes |
Converting by hand
To decimal: multiply each digit by its positional value and sum. Binary 1101 = 8 + 4 + 0 + 1 = 13. Hex 2F = 2×16 + 15 = 47.
From decimal: divide repeatedly by the base and read the remainders bottom to top. For 156 to binary: 156÷2=78 r0, 78÷2=39 r0, 39÷2=19 r1, 19÷2=9 r1, 9÷2=4 r1, 4÷2=2 r0, 2÷2=1 r0, 1÷2=0 r1 → 10011100.
Why hex and not something else
Sixteen is 2⁴, so exactly four binary digits map to one hex digit — with no arithmetic at all.
| Binary | Hex | Binary | Hex |
|---|---|---|---|
| 0000 | 0 | 1000 | 8 |
| 0001 | 1 | 1001 | 9 |
| 0010 | 2 | 1010 | A |
| 0011 | 3 | 1011 | B |
| 0100 | 4 | 1100 | C |
| 0101 | 5 | 1101 | D |
| 0110 | 6 | 1110 | E |
| 0111 | 7 | 1111 | F |
A byte is eight bits, so exactly two hex digits: 11111111 is FF is 255. This is why colours are written #RRGGBB — six hex digits, two per channel, each ranging 00 to FF.
Octal works the same way with three bits per digit, which is why Unix permissions are octal: 755 is 111 101 101, and each group is read/write/execute for owner, group and others.
Notation prefixes
| Prefix | Base | Example |
|---|---|---|
0b | Binary | 0b1101 |
0o or leading 0 | Octal | 0o755 |
0x | Hexadecimal | 0x2F |
# | Hex colour | #3B82F6 |
A leading zero meaning octal is a genuine hazard in older C-family languages: 010 is 8, not 10. Several bugs in date and time handling have come from parsing '08' and '09' as octal, where those digits are not even valid.
Bases beyond 16
Base 32 and base 36 use letters beyond F and appear in short URL identifiers and licence keys. Base 58 — used in cryptocurrency addresses — deliberately omits 0, O, I and l because they are easily confused when read or transcribed by a human, which is a nice example of a design choice made for people rather than machines.