Number Systems: Hexadecimal and Octal Representation
In Week 2, we learned that digital computers operate strictly in binary (0s and 1s). However, humans find long strings of binary digits exhausting and prone to error.
Imagine trying to read a 64-bit computer memory address written in binary:
Your eyes would blur after ten seconds! A programmer attempting to debug that line would inevitably mistype a 0 or a 1.
To solve this, computer scientists use Hexadecimal (Base 16) as a compact, human-readable shorthand for binary. In this lesson, we will master Hexadecimal and Octal, learn the 4-bit Nibble Grouping technique, and discover how hex powers memory addresses and website color palettes.
Learning Outcomes
By the end of this lesson, you will be able to:
- State the radix (base) and symbol set for Hexadecimal (0–9, A–F) and Octal (0–7).
- Convert effortlessly between Binary and Hexadecimal using 4-bit nibble grouping.
- Convert between Binary and Octal using 3-bit grouping.
- Deconstruct 24-bit RGB Hexadecimal Color Codes used in web design.
Key Vocabulary
| Term | Technical Meaning |
|---|---|
| Hexadecimal (Base 16) | A positional number system using sixteen symbols: 0 through 9 and A through F. |
| Octal (Base 8) | A positional number system using eight symbols: 0 through 7. |
| Nibble | A group of 4 binary bits ($2^4 = 16$), mapping directly to exactly 1 hexadecimal digit. |
| RGB Color Code | A 24-bit color representation combining Red, Green, and Blue bytes (e.g., #16324F). |
Prefix 0x |
Standard programming notation indicating that a number is in hexadecimal (e.g., 0xFF). |
The Master Hexadecimal Conversion Table
| Decimal (Base 10) | 4-Bit Binary | Hexadecimal (Base 16) |
|---|---|---|
| 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 |
Method: Binary to Hexadecimal (4-Bit Grouping)
Because $16 = 2^4$, each hexadecimal character represents exactly 4 binary bits:
Conversion Steps:
- Start at the binary number's rightmost digit (LSB) and divide the bits into groups of 4 bits (nibbles).
- If the leftmost group has fewer than 4 bits, pad it with leading zeros on the left.
- Replace each 4-bit nibble with its matching Hexadecimal symbol from the table.
Example 1: Convert $(11010110)_2$ to Hexadecimal
- Group from the right:
[1101]and[0110] - Left nibble: $1101_2 = 8 + 4 + 1 = 13_{10} = \mathbf{D}_{16}$
- Right nibble: $0110_2 = 4 + 2 = 6_{10} = \mathbf{6}_{16}$
- Result: $(11010110)2 = \mathbf{D6$ (or }
0xD6)
Example 2: Convert $(10111)_2$ to Hexadecimal
- Group from the right:
[1] [0111] - Pad leftmost group with leading zeros:
[0001] [0111] - Left: $0001_2 = \mathbf{1}_{16}$
- Right: $0111_2 = 4 + 2 + 1 = \mathbf{7}_{16}$
- Result: $(10111)2 = \mathbf{17$ (or }
0x17)
Real-World Application: 24-Bit RGB Web Colors
In CSS stylesheets and web graphics, colors are defined using Hexadecimal Color Codes: - A 24-bit color contains three bytes (8 bits each): Red, Green, and Blue. - Each 8-bit byte is written as two hexadecimal characters ($00$ to $\text{FF}$, representing 0 to 255 in decimal):
$$\mathbf{#16324F} \implies \text{Red: } 16_{16} \ (22), \quad \text{Green: } 32_{16} \ (50), \quad \text{Blue: } 4F_{16} \ (79)$$
This exact hex code #16324F is the deep, sophisticated Navy Blue color used across our Kinspire DigiLearn learning platform!
Practical Class Activity: Hexadecimal Conversion Drills
Solve the following exercises in your notebook:
- Convert Binary to Hexadecimal:
- a) $(11110000)2 \implies [1111][0000] = \mathbf{F0$}
- b) $(10101111)2 \implies [1010][1111] = \mathbf{AF$}
- c) $(100101)2 \implies [0010][0101] = \mathbf{25$}
- Convert Hexadecimal to Binary:
- a) $\text{3B}_{16} \implies 3 = 0011, \ \text{B} = 1011 \implies \mathbf{00111011_2}$
- b) $\text{FF}_{16} \implies \text{F} = 1111, \ \text{F} = 1111 \implies \mathbf{11111111_2}$
Common Mistakes & Corrections
| Common Mistake | Why It Is Incorrect | Proper Correction |
|---|---|---|
| "Grouping bits into 4 from left to right." | Positional units start at the rightmost LSB ($2^0$); grouping from the left corrupts place values! | Always group binary bits from right to left (LSB to MSB). |
| "Writing '10' instead of 'A' in Hexadecimal." | '10' in Hex means $(1 \times 16) + (0 \times 1) = 16_{10}$, not ten! | Use single letters for double-digit values: A=10, B=11, C=12, D=13, E=14, F=15. |
Notebook Summary
Copy Into Your Computing Notebook
- Hexadecimal (Base 16): Digits 0–9 and letters A–F (where A=10, B=11, C=12, D=13, E=14, F=15).
- Nibble Grouping: 1 Hex digit equals exactly 4 binary bits ($2^4 = 16$).
- Group binary bits from right to left in chunks of 4.
- Hexadecimal is universally used for memory addresses (
0x7FFF), machine code dumps, and HTML web colors (#16324F).