Resources | Subject Notes | Computer Science
This section explains how to convert numbers between the decimal (base-10) and hexadecimal (base-16) number systems. Understanding these conversions is crucial for working with data representation in computer science.
To convert a decimal number to hexadecimal, we repeatedly divide the decimal number by 16 and record the remainders. The remainders, read in reverse order, form the hexadecimal equivalent.
Hexadecimal uses the digits 0-9 and the letters A-F to represent values 10-15. A=10, B=11, C=12, D=13, E=14, F=15.
Example: Convert the decimal number 255 to hexadecimal.
Decimal | Hexadecimal |
---|---|
0 | 0 |
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
7 | 7 |
8 | 8 |
9 | 9 |
10 | A |
11 | B |
12 | C |
13 | D |
14 | E |
15 | F |
16 | 10 |
17 | 11 |
18 | 12 |
19 | 13 |
20 | 14 |
21 | 15 |
22 | 16 |
23 | 17 |
24 | 18 |
25 | 19 |
26 | 1A |
27 | 1B |
28 | 1C |
29 | 1D |
30 | 1E |
31 | 1F |
To convert a hexadecimal number to decimal, we multiply each digit by the corresponding power of 16 and sum the results.
The rightmost digit represents $16^0$, the next digit to the left represents $16^1$, and so on.
Example: Convert the hexadecimal number 3A to decimal.
$3A_{16} = (3 \times 16^1) + (A \times 16^0) = (3 \times 16) + (10 \times 1) = 48 + 10 = 58$.
Hexadecimal | Decimal |
---|---|
0 | 0 |
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
7 | 7 |
8 | 8 |
9 | 9 |
A | 10 |
B | 11 |
C | 12 |
D | 13 |
E | 14 |
F | 15 |
Understanding these conversions is fundamental to data representation, as hexadecimal is often used to represent memory addresses and other low-level data.