← Binary Course — Part A, lesson 4 of 4 (Counting in other bases)
4. Converting Between Binary, Hex, and Decimal by Hand
The concept
Lessons 2 and 3 already cover every conversion this lesson needs — nothing here is a new technique. What's new is the strategy for combining them, and that strategy isn't the same in both directions.
Lesson 2 gave a direct path between binary and decimal (place value, in both directions), and Lesson 3 gave a direct path between binary and hex (the nibble table, in both directions). That leaves decimal and hex without a path of their own — but only one direction actually needs one:
decimal → hex no shortcut: pivot through binary
(Lesson 2, then Lesson 3)
hex → decimal direct: same place-value idea as Lesson 2,
just with powers of 16 instead of powers of 2
Building a hex digit from a decimal number means asking, at each position, "how many times does this place value fit?" — a division, not the simple yes/no test Lesson 2's binary method uses at each of its 8 positions. So for decimal → hex, pivoting through binary really is the easier hand method: it trades one division problem for eight yes/no checks. But reading a decimal value out of hex digits that already exist is just multiplication and addition — no division, no detour needed. That's the same place-value idea Lesson 2 opened with ("each position is worth the base raised to a power"), just instantiated at base 16 instead of base 2.
Example 1 — decimal to hex, through binary
Take decimal 214. First, Lesson 2's method: find which place values sum to it.
128 ≤ 214 → bit 7 = 1, remainder 214 − 128 = 86
64 ≤ 86 → bit 6 = 1, remainder 86 − 64 = 22
32 ≤ 22? no → bit 5 = 0
16 ≤ 22 → bit 4 = 1, remainder 22 − 16 = 6
8 ≤ 6? no → bit 3 = 0
4 ≤ 6 → bit 2 = 1, remainder 6 − 4 = 2
2 ≤ 2 → bit 1 = 1, remainder 2 − 2 = 0
1 ≤ 0? no → bit 0 = 0
That gives 1101 0110. Now Lesson 3's method: convert each nibble.
1101 → 13 → d
0110 → 6
214 is 1101 0110 in binary, and 0xd6 in hex.
Example 2 — hex to decimal, directly
Take 0x9e. No binary needed this time — Lesson 3's table already gives
each hex digit's decimal value (its middle column), so just multiply each
digit by its place value and add. A two-digit hex number only has a ones
place (16⁰ = 1) and a sixteens place (16¹ = 16):
9 × 16 = 144
e (14) × 1 = 14
144 + 14 = 158
0x9e is 158 — one lookup, one multiplication, one addition.
Example 3 — three names, one value
Binary, hex, and decimal are never three different numbers — they're three
different ways of writing the same one. Take 1010 0111:
binary: 1010 0111
hex: a → 1010, 7 → 0111, so 0xa7
decimal: bits 7, 5, 2, 1, 0 → 128 + 32 + 4 + 2 + 1 = 167
1010 0111, 0xa7, and 167 are the same value, just written three ways.
Whichever one a problem hands over, the other two are only a nibble-table
lookup and a place-value sum away.
Exercises
Exercise 1. Using Example 1's method, what's the hex form of decimal 91?
Exercise 2. Using Example 2's method, what decimal value does 0x8d
represent?
Exercise 3. A classmate converts decimal 87 to hex by just writing the
same digits with a 0x in front: 0x87. What's wrong with that shortcut,
and what's the correct hex value?
Show Answer Key
1. 91 = 64 + 16 + 8 + 2 + 1, so bits 6, 4, 3, 1, and 0 are set:
0101 1011. Converting each nibble: 0101 → 5, 1011 → 11 → b. Decimal
91 is 0x5b.
2. 8 is 8, d is 13. 8 × 16 = 128, 13 × 1 = 13, and
128 + 13 = 141. 0x8d is 141.
3. The shortcut assumes hex digits are just decimal digits relabeled
with a 0x in front, but a hex digit's place value is a power of 16, not a
power of 10 — 0x87 actually means 8×16 + 7×1 = 135, a completely
different value from decimal 87. The same digits mean different things
depending on which base they're read in, exactly like Lesson 1 and 2's
bit-indexing mistakes were the same symbols read the wrong way. The correct
value: 87 = 64 + 16 + 4 + 2 + 1, so bits 6, 4, 2, 1, and 0 are set:
0101 0111. Converting each nibble: 0101 → 5, 0111 → 7. Decimal 87 is
0x57.
With this lesson, Part A is complete: any whole number in this course can now be moved freely between binary, hex, and decimal by hand. Part B picks up from here and starts doing things to the bits themselves — AND, OR, XOR, NOT, and shifts.
Sign in to mark lessons complete and keep your progress.