Convert between positive denary and positive hexadecimal

Resources | Subject Notes | Computer Science

Data Representation: Converting Between Decimal and Hexadecimal

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.

Decimal to Hexadecimal Conversion

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.

  1. Divide 255 by 16: $255 \div 16 = 15$ with a remainder of $15$.
  2. The remainder 15 corresponds to the hexadecimal letter F.
  3. The quotient is 15, which is also a remainder. Divide 15 by 16: $15 \div 16 = 0$ with a remainder of $15$.
  4. The remainder 15 corresponds to the hexadecimal letter F.
  5. The quotient is 0, so we stop.
  6. Reading the remainders in reverse order gives us FF.
  7. Therefore, the decimal number 255 is equal to the hexadecimal number FF.

Conversion Table (Decimal 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

Hexadecimal to Decimal Conversion

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$.

Conversion Table (Hexadecimal to Decimal)

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

Summary

Understanding these conversions is fundamental to data representation, as hexadecimal is often used to represent memory addresses and other low-level data.