Converting Between Decimal and Hexadecimal
Decimal to Hexadecimal
- Divide by 16: Continuously divide the decimal number by 16, keeping track of the quotient and remainder at each step.
- Record Remainders: The remainders will be the hexadecimal digits, starting from the last remainder and going upwards.
- Convert to Hexadecimal Digits: Convert any remainders greater than 9 to their corresponding hexadecimal letter (A=10, B=11, C=12, D=13, E=14, F=15).
Example: Convert the decimal number 255 to hexadecimal.
255 / 16 = 15 (remainder 15, or F in hexadecimal)
15 / 16 = 0 (remainder 15, or F in hexadecimal)
Therefore, 255 in decimal is FF in hexadecimal.
Hexadecimal to Decimal
- Identify Place Values: Each digit in a hexadecimal number represents a power of 16, starting from the rightmost digit as 160, then 161, 162, and so on.
- Multiply and Sum: Multiply each hexadecimal digit by its corresponding power of 16.
- Add the Results: Add the results of the multiplications to get the decimal equivalent.
Example: Convert the hexadecimal number A2 to decimal.
A = 10 (in decimal)
2 = 2 (in decimal)
A2 = (10 * 16<sup>1</sup>) + (2 * 16<sup>0</sup>)
= (160) + (2)
= 162
Therefore, A2 in hexadecimal is 162 in decimal.