π’ Hexadecimal Conversion
π’ Working with Hexadecimal Numbers
Hexadecimal (base-16) is a number system commonly used in computing as a more human-friendly way to represent binary data. Understanding hexadecimal and how to convert between number systems is an essential skill in information technology.
π Hexadecimal Number Systemβ
What is Hexadecimal?β
- A base-16 number system
- Uses 16 digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15)
- Position values are powers of 16 (16^0, 16^1, 16^2, etc.)
- Often prefixed with "0x" or suffixed with "h" to indicate hexadecimal
π€ Why Hexadecimal is Usedβ
- Compact representation of binary data
- One hexadecimal digit represents exactly 4 binary digits (bits)
- Easier for humans to read and write than long binary sequences
- Commonly used for memory addresses, color codes, and machine code
π Hexadecimal to Denary Conversionβ
To convert hexadecimal to denary (base-10):
- Identify the position value of each digit (powers of 16 from right to left)
- Convert each hexadecimal digit to its denary value
- Multiply each digit value by its position value
- Sum all the results
Example 1: Convert 2Fββ to denaryβ
2 F
β β
16^1 16^0
16 1
β β
2Γ16 15Γ1
32 15
Sum: 32 + 15 = 47ββ
Example 2: Convert 1A3ββ to denaryβ
1 A 3
β β β
16^2 16^1 16^0
256 16 1
β β β
1Γ256 10Γ16 3Γ1
256 160 3
Sum: 256 + 160 + 3 = 419ββ
π Denary to Hexadecimal Conversionβ
To convert denary to hexadecimal:
- Divide the number by 16
- Record the remainder (0-15, using A-F for 10-15)
- Continue dividing the quotient by 16 until the quotient becomes 0
- Read the remainders from bottom to top to get the hexadecimal number
Example 1: Convert 250ββ to hexadecimalβ
Division Quotient Remainder
250 Γ· 16 15 10 (A)
15 Γ· 16 0 15 (F)
Reading remainders from bottom to top: FAββ
Example 2: Convert 52ββ to hexadecimalβ
Division Quotient Remainder
52 Γ· 16 3 4
3 Γ· 16 0 3
Reading remainders from bottom to top: 34ββ
π Binary to Hexadecimal Conversionβ
To convert binary to hexadecimal:
- Group the binary digits in sets of 4, starting from the right
- Convert each group of 4 bits to its hexadecimal equivalent
- Combine the hexadecimal digits
Example 1: Convert 1010 1101β to hexadecimalβ
1010 1101
β β
A D
Result: ADββ
Example 2: Convert 11 1110 0001β to hexadecimalβ
0011 1110 0001
β β β
3 E 1
Result: 3E1ββ
π Hexadecimal to Binary Conversionβ
To convert hexadecimal to binary:
- Convert each hexadecimal digit to its 4-bit binary equivalent
- Combine all binary groups
Example 1: Convert C5ββ to binaryβ
C 5
β β
1100 0101
Result: 1100 0101β
Example 2: Convert 2FAββ to binaryβ
2 F A
β β β
0010 1111 1010
Result: 0010 1111 1010β
π Common Hexadecimal Values to Rememberβ
Hex | Binary | Denary | Hex | Binary | Denary | |
---|---|---|---|---|---|---|
0 | 0000 | 0 | 8 | 1000 | 8 | |
1 | 0001 | 1 | 9 | 1001 | 9 | |
2 | 0010 | 2 | A | 1010 | 10 | |
3 | 0011 | 3 | B | 1011 | 11 | |
4 | 0100 | 4 | C | 1100 | 12 | |
5 | 0101 | 5 | D | 1101 | 13 | |
6 | 0110 | 6 | E | 1110 | 14 | |
7 | 0111 | 7 | F | 1111 | 15 |
π» Practical Applicationsβ
Hexadecimal is commonly used in:
- π§ Memory addresses in programming and debugging
- π¨ Color codes in web design (e.g., #FF0000 for red)
- π MAC addresses for network interfaces
- π File signatures and hexadecimal editors
- π₯οΈ Assembly language and machine code representation
Understanding hexadecimal conversion is essential for many aspects of computer science and digital systems work.