And finally, a brief excursion into hexadecimal numbers:
Activity5.6.
Please convert the decimal number 20,000 into hexadecimal.
Answer.
0x4E20
Binary is the native number system of the computer, but it is often convenient for us to talk in the hexadecimal number system (HEX), that is, in base-16.
HEX digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (0-15)
Example: 0xAC means "A" * \(16^1\) + "C" * \(16^0\) = 10 * 16 + 12 * 1 = 172 in decimal
The "0x" indicates that what follows is in hex
Another example: 0x57 means 5 * \(16^1\) + 7 * \(16^0\) = 87 in decimal
Subsection5.4.1Why Use Hexadecimal?
Binary numbers can be REALLY long (used in memory location addressing for example.)
Need: easy shorthand for binary
Solution: HEX
Condense 4 bits (binary digits) into 1 hexadecimal digit
Example: 1011 binary = 11 decimal = B hexadecimal
2-byte words (16 bits) can then be written as four HEX digits
We want powers of 2 (binary) for easy conversion.
Alternative?
Octal (digits 0-7)
Condenses 3 bits into one
Subsection5.4.2Decimal to Hexadecimal
We already know how this works: keep dividing by 16, record the remainders in reverse order!