Page 325 - Embedded Microprocessor Systems Real World Design
P. 325
1,234 = lOOllOlOOlOb = 4D2h
Sometimes a lowercase d suffix is used to indicate decimal numbers, but if this method
is used, the hex numbers must always use uppercase digits (ABCDEF). Otherwise, you can’t
tell if the d indicates a decimal number or the hex digit D.
It is important to remember that microprocessors do not operate with hex numbers; they
operate in binary. Hexadecimal is just a convenient representation for people to use when
working with binary numbers.
In the early days of computers, octal was often used. This was just another representa-
tion, where the binary numbers were divided into groups of 3 bits. Each group could range
from zero to 7, and the digits went up by powers of 8 (1, 8, 64, and so on). 123410 = 2322*.
Octal is rarely used now.
So why use 4bit groups? Why not create a number system that uses 5-bit groups, where
the values ranged from zero to 31? You could, and it would let you represent numbers up
to 1023 with two digits. But you would need 32 unique characters for the digits, and you
would have to remember the values of all of them. More importantly, microprocessor data
and (usually) address buses come in increments of 8 bits, so the hexadecimal system is more
practical for real systems.
Converting Numbers Between Bases
We often need to convert numbers between hex, decimal, and binary. The simplest way, of
course, is to use a calculator that can convert between bases. However, it is important to
understand the methods.
Hex to Binary
Hex to binary conversions are easy. Start with lDEGIG. To convert this to binary, just write
out the binary values that correspond to each hex digit:
Hex: 1 D E 6
Binary: 0001 1101 1110 0110
If you want, take out the spaces: 0001110111100110
Now you can see why hex is easier to use. This is just a 16bit number. Imagine working
with 64bit numbers using binary.
Binary to Hex
Separate the binary number into 4bit groups, starting with the rightmost digit. If the right-
most group doesn’t have 4 bits, append zeros to the left to make 4 bits:
11101111001 10 becomes 1 1101 1110 0110
Append zeros on the left: 0001 1101 1110 0110
Then convert each 4bit group to a hex digit:
306 Appendix B