9.5 Hexadecimal Notation
COS2621 - Computer Organisation · 9. Number Systems
9.5 Hexadecimal Notation
Hexadecimal notation is a base-16 number system. It uses sixteen symbols: the digits 0 to 9 and the letters A to F. In this system, A represents the decimal value 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15. Hexadecimal is commonly used in computing because it is more compact than binary and easier for humans to read.
Why Use Hexadecimal?
Hexadecimal is used to represent large binary numbers more conveniently. Each hexadecimal digit corresponds to four binary digits (bits). For example, the hexadecimal number 4B can be converted to binary as follows:
4 = 0100
B = 1011
Thus, 4B in binary is 0100 1011.
Converting Decimal to Hexadecimal
To convert a decimal number to hexadecimal, use the division method. Divide the decimal number by 16 and record the remainder. Repeat this process with the quotient until it reaches zero. The hexadecimal number is formed by reading the remainders in reverse order.
Example: Convert 1024 to hexadecimal.
1024 ÷ 16 = 64 remainder 0
64 ÷ 16 = 4 remainder 0
4 ÷ 16 = 0 remainder 4Reading the remainders from bottom to top gives you 400. Thus, 1024 in decimal is 400h in hexadecimal.
Converting Hexadecimal to Decimal
To convert a hexadecimal number to decimal, multiply each digit by 16 raised to the power of its position (starting from 0 on the right).
Example: Convert 2F3 to decimal.
2F3 = 2 × 16^2 + F × 16^1 + 3 × 16^0
= 2 × 256 + 15 × 16 + 3 × 1
= 512 + 240 + 3 = 755.Thus, 2F3 in decimal is 755.
Hexadecimal Addition
Hexadecimal addition follows the same rules as decimal addition but with base 16. If the sum exceeds 15, you carry over to the next digit.
Example: Calculate (1Fh + 9Ch).
1F = 1 × 16^1 + F × 16^0 = 31
9C = 9 × 16^1 + C × 16^0 = 156
Now add: 31 + 156 = 187.We convert 187 to hexadecimal:
187 ÷ 16 = 11 remainder 11 (B)
11 ÷ 16 = 0 remainder 11 (B)Thus, 1Fh + 9Ch = BBh.
Watch out: Students often confuse hexadecimal digits with decimal values. Remember that A, B, C, D, E, and F represent 10, 11, 12, 13, 14, and 15, respectively.
Hexadecimal in Computing
Hexadecimal notation is widely used in programming and computer science. Memory addresses and colour codes in web design often use hexadecimal values. For example, the colour blue is represented as #0000FF in hexadecimal.
Practice Questions
- Convert the decimal number 512 to hexadecimal.
- What is the decimal equivalent of the hexadecimal number 7E?
- Calculate (A5h + 2Bh).
- Convert the hexadecimal number C7AEh to binary.
For the conversion of C7AEh to binary, we convert each hexadecimal digit:
C = 1100
7 = 0111
A = 1010
E = 1110Thus, C7AEh in binary is 1100 0111 1010 1110.
Test yourself
5 quick questions on this lesson. Pick an answer to see if you're right.
1. Calculate (74)16 - (3A)16
2. Calculate (3A69) 16 + (B2E1)16.
3. Calculate (3A69)16 + (B2E1)16
4. Which hexadecimal digit represents the decimal value 15?
5. Why is hexadecimal notation preferred in programming?