Reading 3: Hexadecimal: A Shorthand for Binary

Let's talk about hex baby.

Why Learn Hexadecimal?

In earlier readings, you saw how to represent integers using 8 bits (one byte) and how to convert between binary and decimal. You may have also noticed that binary strings get long quickly, even for relatively small numbers.

Hexadecimal, or hex, is a more compact and readable way to represent binary values. It doesn’t change the data; it simply gives humans a shorter code for the same underlying bit patterns.

You can think of hex as an abbreviation for binary — the same meaning, just written in a shorter, more readable form.

Hexadecimal Is Base 16

Just as decimal is base 10 (using digits 0–9) and binary is base 2 (using digits 0 and 1), hexadecimal is base 16. It uses 16 symbols:

0–9 and A, B, C, D, E, F

The letters represent the values 10 through 15:

Hex Decimal
A 10
B 11
C 12
D 13
E 14
F 15

Why 1 Hex Digit = 4 Bits

A 4‑bit binary number (often called a nibble) can represent 16 different values: 0–15. That matches perfectly with the 16 symbols in hexadecimal.

This gives us a very clean mapping:

1 hex digit ↔ exactly 4 bits

Here is the full mapping:

Binary (4 bits) Decimal Hex
0000 0 0
0001 1 1
0010 2 2
0011 3 3
0100 4 4
0101 5 5
0110 6 6
0111 7 7
1000 8 8
1001 9 9
1010 10 A
1011 11 B
1100 12 C
1101 13 D
1110 14 E
1111 15 F

Converting Between Binary and Hex

Because 1 hex digit corresponds exactly to 4 bits, converting between binary and hex is often easier than converting between binary and decimal. The conversion from binary to a decimal integer only uses the values 1, 2, 4, and 8. After converting to decimal, if the number is a single digit then the hex value is the same number. If the number is a double digit number then you convert to its corresponding letter value remembering that 10=A, 11=B, all the way up to 15=F.

Worked Example: Binary → Hex

To convert a binary string to hex, split it into groups of 4 bits starting from the right, then replace each group with its hex digit.

Convert 10110101 to hex:

Step 4-bit group Decimal value Hex digit
Left group 1011 8+2+1 = 11 B
Right group 0101 4+1 = 5 5

Putting the hex digits together left to right:

10110101₂ = 0xB5

The prefix 0x is a common prefix in computer science.  The "x" signals that the number that follows isn't a base-10 or decimal number, it is a hexadecimal number. In the example above, if you saw B5 you would suspect it was hex because of the appearance of B. But if you saw the number 0x48 you would know that this is not the decimal value 48, but the hexadecimal value 48 (which has a decimal value of 4×16+8 = 72).

It is worth pointing out that 0x is not the only prefix used in computer science to denote how a sequence should be interpreted. In this unit we will typically write 10110101 or 10110101₂ to represent a bit string of binary digits. But it is also written as 0b10110101 where the b signals binary.

Worked Example: Hex → Binary

Going the other direction is even simpler: replace each hex digit with its 4-bit pattern.

Convert 0xAF to binary:

Hex digit Decimal value 4-bit pattern
A 10 1010
F 15 1111

Combining the 4-bit groups left to right:

0xAF = 10101111₂

Now You Try

Convert 0x3E from hex to binary, then back again to confirm your answer. Use the mapping table above as a reference. Write down your answer before expanding the solution below.

Show Answer

Hex → Binary:

Hex digit Decimal value 4-bit pattern
3 3 0011
E 14 1110

3E₁₆ = 00111110₂

Verify by converting back (Binary → Hex):

4-bit group Decimal value Hex digit
0011 2+1 = 3 3
1110 8+4+2 = 14 E

00111110₂ = 3E₁₆ ✓

Why Hex Matters in Practice

Binary is the language computers "speak" at the lowest level. But long sequences of 0s and 1s are hard for humans to read and easy to mistype.

Hexadecimal offers a practical compromise: it still maps directly to binary, but it uses fewer symbols to represent the same information. You’ll see hex in many computing contexts:

Good news: many teachers find hexadecimal easier than binary — fewer digits, clear patterns, and a clean 4‑bits‑per‑digit mapping.

For your students, learning hex means discovering that digital systems follow consistent, understandable patterns — patterns you can help them decode.