HEXADECIMAL NUMBERS

Come back. You don't have to run away at the sound of those words. Hex, as its friends call it, is not nearly as hard as everyone thinks it is. As a matter of fact, it's really quite simple. But, just in case you don't believe us, I provide both decimal and hexadecimal numbers throughout the book. Now, though, we're going to learn about hex together.

The main use for hex is in assembly language programming. We're not going to worry about that now though, because it's not really important. Instead, we're going to go back to grade school, where we first learned all about the number system. As you'll recall, we use the decimal number system, which means that everything is based on powers of 10. For example, the number 452 is equal to 4*100+5*10+2*1, right? In other words, 4*10^2+5*10^1+2*10^0. Now you're not going to believe this, but the only difference between decimal and hex is that hex is based on powers of 16 instead of 10. For example, 452 hex would equal 4*16^2+5*16^1+2*16^0 or 4*256+5*16+2, in other words, 1106. Pretty simple, huh? Actually, there's one more thing that I should probably mention. The number 9 in hex is the same as 9 decimal, but 10 hex is 16 decimal (1 * 16^ 1). So how do you write 10, 11, 12, 13, 14, and 15 decimal in hex? Try A, B, C, D, E, and F! That's why hex numbers look so confusing. So, for example, F in hex equals 15 decimal, 1F equals 31 (16+15), and so on. Oh, and by the way, binary is actually the same as hex and decimal, except it counts in powers of 2!

Don't worry, I'm not going to leave you yet. A few more examples should make you a little more comfortable about hex and how to use it, but first a chart (Table 1) to help us out.

Table 1. Hex Conversion Chart

 
Column #

4th
 
3rd
 
2nd
 
1st
#
HEX


 4096
 8192
12288
16384
20480
24576
28672
32768
36864
40960
45056
49152
53248
57344
61440
 256
 512
 768
1024
1280
1536
1792
2048
2304
2560
2816
3072
3328
3584
3840
 16
 32
 48
 64
 80
 96
112
128
144
160
176
192
208
224
240
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F


Return to Table of Contents | Previous Chapter | Next Chapter