1.1.3 Hexadecimal: A Compact View of Binary
Imagine that a diagnostic tool needs to display the 16-bit pattern 1010001110011111. A technician could read all sixteen binary digits, but a shorter code would be easier to scan, copy and compare.
Hexadecimal provides that shorter notation. The same bit pattern can be written as A39F because every hexadecimal digit corresponds exactly to four binary bits.
By the end of this section, you should be able to:
- explain how the base-16 number system works;
- match each hexadecimal digit to a four-bit binary pattern;
- convert positive binary values to and from hexadecimal;
- convert positive denary values to and from hexadecimal;
- explain why hexadecimal is useful in computer science;
- apply conversions to values represented with up to 16 binary bits.
A number system with sixteen symbols
Denary has ten available digits, while binary has two. Hexadecimal has sixteen symbols available for each digit position.
Base 基数: the number of different digit values available in a number system before a new position is required.
Hexadecimal digit 十六进制数位: one symbol from 0–9 or A–F.
| Number system | Base | Available symbols | Place values |
|---|---|---|---|
| Denary | 10 | 0–9 | 1, 10, 100, 1000, ... |
| Binary | 2 | 0 and 1 | 1, 2, 4, 8, 16, ... |
| Hexadecimal | 16 | 0–9 and A–F | 1, 16, 256, 4096, ... |
The letters A to F provide single symbols for the denary values 10 to 15. This allows every value from 0 to 15 to fit into one hexadecimal position.
Common mistake
The letters do not begin a new alphabetic count. In hexadecimal, A means denary 10, B means 11, and the sequence continues until F means 15.
The sixteen hexadecimal digit values
Each hexadecimal digit matches one possible four-bit pattern. A group of four bits is commonly called a nibble.
Digit mapping 数位映射: a direct match between a hexadecimal digit and its four-bit binary form.
| Denary | Hexadecimal | Four-bit binary | Denary | Hexadecimal | Four-bit binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | 10 | A | 1010 |
| 3 | 3 | 0011 | 11 | B | 1011 |
| 4 | 4 | 0100 | 12 | C | 1100 |
| 5 | 5 | 0101 | 13 | D | 1101 |
| 6 | 6 | 0110 | 14 | E | 1110 |
| 7 | 7 | 0111 | 15 | F | 1111 |
Four bits create 24 = 16 possible patterns. This is why one hexadecimal digit and one nibble fit together perfectly.
Efficient recall
You do not need to memorise sixteen unrelated patterns. Use the four binary place values 8, 4, 2 and 1. For example:
1101 = 8 + 4 + 1 = 13, so the hexadecimal digit is D.
Converting binary to hexadecimal
Convert a binary value using the process group → translate → join.
- Begin at the right of the binary pattern.
- Separate the bits into groups of four.
- Add leading zeros if the leftmost group is incomplete.
- Translate each four-bit group into one hexadecimal digit.
- Join the hexadecimal digits in their original order.
Worked example: convert 101101101101 to hexadecimal
Step 1: separate the bits into nibbles
Step 2: translate each nibble
| Binary group | Calculation | Denary value | Hexadecimal digit |
|---|---|---|---|
| 1011 | 8 + 2 + 1 | 11 | B |
| 0110 | 4 + 2 | 6 | 6 |
| 1101 | 8 + 4 + 1 | 13 | D |
Step 3: join the digits
1011 0110 11012 = B6D16
Common mistake
Group from the right-hand side. If the left group has fewer than four bits, add zeros to its left. Do not add zeros to the right because that would change the value.
When the binary pattern is not a multiple of four bits
Consider the seven-bit value 1011110. Starting from the right gives:
The first group is incomplete, so one leading zero is added:
Now translate the two groups:
- 0101 corresponds to 5;
- 1110 corresponds to E.
10111102 = 5E16
Answer-building tip
Show the four-bit grouping in your working. It makes the direction of the conversion clear and reduces the chance of losing a bit.
Converting hexadecimal to binary
The reverse process is direct. Replace every hexadecimal digit with its complete four-bit binary pattern.
Worked example: convert 7C4 to binary
| Hexadecimal digit | Denary value | Four-bit binary pattern |
|---|---|---|
| 7 | 7 | 0111 |
| C | 12 | 1100 |
| 4 | 4 | 0100 |
Join the three groups:
7C416 = 0111 1100 01002
Common mistake
Each hexadecimal digit must produce exactly four bits. For example, hexadecimal 4 becomes 0100, not merely 100. Keeping four bits preserves the boundaries between hexadecimal digits.
Reading hexadecimal with place values
Hexadecimal is positional. Starting from the right, its place values are powers of 16.
| Power | 163 | 162 | 161 | 160 |
|---|---|---|---|---|
| Place value | 4096 | 256 | 16 | 1 |
A hexadecimal digit contributes:
digit value × place value
Converting hexadecimal to denary
Multiply each hexadecimal digit value by its place value, then add the results.
Worked example: convert 4D7 to denary
| Hexadecimal digit | Digit value | Place value | Contribution |
|---|---|---|---|
| 4 | 4 | 256 | 4 × 256 = 1024 |
| D | 13 | 16 | 13 × 16 = 208 |
| 7 | 7 | 1 | 7 × 1 = 7 |
1024 + 208 + 7 = 1239
Therefore:
4D716 = 123910
Common mistake
Do not read D as the separate decimal digits 1 and 3. D is one hexadecimal digit with the value 13.
Converting denary to hexadecimal
One direct method is repeated division by 16. Each remainder identifies one hexadecimal digit.
- Divide the denary value by 16.
- Record the whole-number quotient and remainder.
- Divide the quotient by 16 again.
- Continue until the quotient becomes zero.
- Read the remainders from the final one back to the first.
Worked example: convert denary 746 to hexadecimal
| Division | Whole-number quotient | Remainder | Hexadecimal remainder |
|---|---|---|---|
| 746 ÷ 16 | 46 | 10 | A |
| 46 ÷ 16 | 2 | 14 | E |
| 2 ÷ 16 | 0 | 2 | 2 |
Read the hexadecimal remainders from bottom to top:
74610 = 2EA16
Check using hexadecimal place values
(2 × 256) + (14 × 16) + 10 = 512 + 224 + 10 = 746
Common mistake
The remainders are produced from the least significant digit to the most significant digit. Reading them in the order they were generated would reverse the hexadecimal answer.
Why hexadecimal is a compact view of binary
The relationship is exact because one hexadecimal digit always replaces four binary bits.
| Binary width | Number of nibbles | Hexadecimal width | Example |
|---|---|---|---|
| 4 bits | 1 | 1 digit | 1110 = E |
| 8 bits | 2 | 2 digits | 1011 0010 = B2 |
| 12 bits | 3 | 3 digits | 0011 0111 1100 = 37C |
| 16 bits | 4 | 4 digits | 1010 0011 1001 1111 = A39F |
The maximum positive 16-bit pattern is:
1111 1111 1111 11112 = FFFF16 = 6553510
Useful relationship
To predict the hexadecimal width, divide the binary width by four. A 16-bit pattern therefore requires four hexadecimal digits.
Why hexadecimal is used
Computers ultimately store and process bit patterns. Hexadecimal is a convenient notation that allows people to view the same patterns more compactly.
| Benefit | Practical consequence |
|---|---|
| Shorter than binary | Long bit patterns occupy less screen or page space. |
| Clear four-bit grouping | Every hexadecimal digit can be translated directly into one nibble. |
| Easier to compare | Differences between two long values are more visible to a person. |
| Easier to copy | Fewer symbols reduce the opportunity to omit or duplicate a digit. |
Common mistake
Hexadecimal is not “more understandable” to the processor. It is useful because it gives people a shorter representation of the underlying binary pattern.
Develop the benefit
Avoid writing only “hexadecimal is shorter”. Explain the consequence:
Hexadecimal uses one digit for every four binary bits, so a long binary value requires fewer symbols and is easier for a person to read and compare.
Where hexadecimal appears in computer science
Hexadecimal is especially helpful when people need to inspect, configure or describe data that is fundamentally stored as bits.
| Application | How hexadecimal helps | Example form |
|---|---|---|
| Memory addresses | Locations in memory can be displayed using fewer symbols than binary. | 0x3A7C |
| Debugging and diagnostic data | Developers can compare low-level values more quickly. | 8F2D |
| Colour values | Red, green and blue channel values can each be represented by two hex digits. | #4CA7D2 |
| Hardware addresses | Groups of binary data can be presented as pairs of hexadecimal digits. | 7A:31:C0:58:2D:9F |
| Machine-level data | Bytes and instructions can be inspected without displaying every bit. | A4 0F 72 |
Prefix 前缀: a marker placed before a number to identify its notation. In many programming contexts,
0x indicates hexadecimal.
The exact notation depends on the system. A hexadecimal value may be labelled with a prefix, a suffix, a colour marker or surrounding context.
Interactive: Hexadecimal Conversion Laboratory
Enter a value in denary, binary or hexadecimal. The laboratory keeps all three representations synchronised and shows how the binary pattern divides into nibbles.
Choose the efficient route
For binary and hexadecimal, use four-bit groups. For hexadecimal and denary, use powers of 16 or repeated division by 16.
Practice
Core questions
- State the base and available symbols of hexadecimal.
- Write the denary values represented by hexadecimal A, C, E and F.
- Convert 111001011010 into hexadecimal.
- Convert 001101111100 into hexadecimal.
- Convert hexadecimal 5B2 into 12-bit binary.
- Convert hexadecimal D20 into 12-bit binary.
- Convert denary 1965 into hexadecimal.
- Convert denary 4094 into hexadecimal.
- Convert hexadecimal 8E6 into denary.
- Convert hexadecimal 3B9 into denary.
- Explain why hexadecimal is more convenient than binary for a person inspecting a long bit pattern.
- Identify two areas of computer science in which hexadecimal notation may be used.
Extension questions
- Convert 1011110000100111 into hexadecimal and denary.
- Convert hexadecimal C84F into 16-bit binary and denary.
- Explain why one hexadecimal digit can replace exactly four binary bits.
- A diagnostic value is displayed as 3A7E. A second value is displayed as 3AFE. Explain why hexadecimal makes the difference easier to locate than the equivalent binary patterns.
- A student converts binary 101101 into hexadecimal by grouping it as 1011 01. Explain the error and give the correct hexadecimal result.
Check the numerical answers
- A = 10, C = 12, E = 14 and F = 15.
- 111001011010 = E5A.
- 001101111100 = 37C.
- 5B2 = 0101 1011 0010.
- D20 = 1101 0010 0000.
- 1965 = 7AD.
- 4094 = FFE.
- 8E6 = 2278.
- 3B9 = 953.
- 1011110000100111 = BC27 = 48167.
- C84F = 1100 1000 0100 1111 = 51279.
- 101101 must be padded and grouped as 0010 1101, giving 2D.
Review
Key ideas
- Hexadecimal is a base-16 number system.
- It uses the symbols 0–9 and A–F.
- A–F represent the denary values 10–15.
- One hexadecimal digit corresponds exactly to four binary bits.
- Binary is converted to hexadecimal by grouping bits from the right.
- Hexadecimal is converted to binary by replacing every digit with four bits.
- Hexadecimal place values are powers of 16.
- Repeated division by 16 can convert denary to hexadecimal.
- Hexadecimal gives people a shorter way to display binary values.
- A 16-bit value can be represented using four hexadecimal digits.
Quick self-check
- Can I recall the values of hexadecimal A–F?
- Can I translate a hexadecimal digit into four binary bits?
- Can I group a binary value correctly from the right?
- Can I use powers of 16 to calculate a denary value?
- Can I use repeated division to construct a hexadecimal value?
- Can I explain a practical benefit of hexadecimal?
One-minute exit task
Convert binary 101011110011 into hexadecimal. Then convert your hexadecimal answer into denary.