01/08/14
1
An Introduction to Computer An Introduction to Computer
Hardware - BKHSHardware - BKHS
Hexadecimal Numbers
01/08/14
2
Introduction to HexadecimalIntroduction to Hexadecimal
• Base-16 number system
•16 Unique symbols
•Numbers 0 to 9 and letters A to F
•Decimal 10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F
•Can represent every byte (8 bits) as two hexadecimal
digits
•Easier for humans to read hexadecimal rather than
binary
•Hexadecimal numbers usually have either an 0x prefix
or an h suffix.
Example: 0x3F7A, 85D2h
01/08/14
3
Converting Decimal to HexConverting Decimal to Hex
1.Divide the decimal number by 16. Treat the division
as an integer division.
2.Write down the remainder (in hexadecimal).
3.Divide the result again by 16. Treat the division as an
integer division.
4.Repeat step 2 and 3 until result is 0.
5.The hex value is the digit sequence of the remainders
from the last to first.
01/08/14
4
Decimal to Hex ExampleDecimal to Hex Example
Convert 837 to Hex
837/16 = 52 r 5 Least significant
52/16 = 3 r 4
3/16 = 0 r 3 Most Significant
0x345 or 345h
01/08/14
5
Converting Hex to DecimalConverting Hex to Decimal
1.Get the last digit (LSD) of the hex number, call
this digit the currentDigit.
2.Make a variable, let's call it power. Set the value
to 0.
3.Multiply the current digit with (16^power), store
the result.
4.Increment power by 1.
5.Set the the currentDigit to the previous digit of
the hex number.
6.Repeat from step 3 until all digits have been
multiplied.
7.Sum the result of step 3 to get the answer number
01/08/14
6
Hex to Decimal ExampleHex to Decimal Example
Convert 0x58B to Decimal
Last digit (LSD) = 0xB = 11(decimal)
16^0 = 1, 1 x 11 = 11
Next digit = 8
16^1 = 16, 8 x 16 = 128
Next digit (MSD) = 5
16^2 = 256, 5 x 256 = 1280
1280 + 128 + 11 = 1409 decimal
01/08/14
6
Hex to Decimal ExampleHex to Decimal Example
Convert 0x58B to Decimal
Last digit (LSD) = 0xB = 11(decimal)
16^0 = 1, 1 x 11 = 11
Next digit = 8
16^1 = 16, 8 x 16 = 128
Next digit (MSD) = 5
16^2 = 256, 5 x 256 = 1280
1280 + 128 + 11 = 1409 decimal