Digital Signal Processing Reference
In-Depth Information
1.1.3
Why Do Programmers Sometimes Use Base 16
(Hexadecimal)?
Computers use binary, which is great for a computer, but dicult for a human. For
example, which is easier for you to remember, 0011001000010101 or 3215? Actually,
these two numbers are the same, the rst is in binary and the second is in hexadec-
imal. As you can see, hexadecimal provides an easier way for people to work with
computers, and it translates to and from binary very easily. In fact, one hexadecimal
digit represents four bits. With a group of four bits, the only possibilities are: 0000,
0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110,
and 1111. These 16 possible combinations of 4 bits map to the numbers 0, 1, 2, 3, 4,
5, 6, 7, 8, 9. At this point, we have a problem, since we would be tempted to make
the next number \10," as we would in decimal. The problem with this is that it is
ambiguous: would \210" mean 2, 1, 0, or would it mean 2, 10? Since we have 16
dierent values in a group of four binary digits, we need 16 dierent symbols, one
symbol for each value. This is why characters from the alphabet are used next: A,
B, C, D, E, and F.
It is inecient to use 1-bit registers, so computers group bits together into a
word. The word size is dependent on the architecture (e.g., the \64" in the Nin-
tendo 64 stands for the 64-bit word size of its processor). Typically, the word size
is a multiple of a byte (8 bits), and hexadecimal numbers work nicely with such
machines. For example, a machine with a 1-byte word size would work with data
sizes of 2 hexadecimal digits at a time. A 16-bit word size means 4 hexadecimal
digits are used.
Here is an example demonstrating word size. Suppose we have two multiplica-
tions,
93
46329187:
We can do both of the above multiplications, but most people have an immediate
answer for the one on the left, but need a minute or two for the one on the right.
Why? While they might have the single-digit multiplication answers memorized,
they use an algorithm for the multiple digit multiplications, i.e., multiply the right-
most digits, write the result, write the carry, move one digit to the left, for the
\top" number, and repeat the process. In a sense, we have a 1-digit word size when
performing this calculation. Similarly, a computer will multiply (or add, subtract,
etc.) in terms of its word size. For example, suppose that a computer has a word
size of 8 bits. If it needed to increment a 16-bit number, it would add one to the
low 8 bits, then add the carry to the high 8 bits.
Search WWH ::




Custom Search