E. Hexadecimals"Regular" numbers are based on the base 10 system, that is, there are ten symbols (what we call "numbers"): 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. To represent numbers greater than 9, we use a combination of these symbols where the first digit specifies how many ones, the second digit (to the left) specifies how many tens, and so on. In the hexadecimal system, which is base 16, there are sixteen symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, and f. To represent numbers greater than f (which in base 10 we understand as 15), we again use a combination of symbols. This time the first digit specifies how many ones, but the second digit (again, to the left) specifies how many sixteens. Thus, 10 in the hexadecimal system means one sixteen and no ones. In the base 10 system, it'd be 16. In (X)HTML and CSS, hexadecimal numbers are used to define colors (see page 126) and to insert symbols (see page 336). While you can convert hexadecimal numbers by hand, I've also included a table to help you quickly look up a number's hexadecimal equivalent. Figure E.1. Hexadecimal numbers are base 16, that is the first digit (starting on the right) represents the ones, the second digit represents the 16's, the third digit represents the 256's, and so on.
So, to use this chart, imagine you want to find the hex value for a color with 35% red, 0% green, and 50% blue. The percentages are relative to 255, so 35% x 255 = 89. Now, find the hexadecimal equivalent of 89, near the bottom of the third column above. So for red, we have 59. Green is easy; 0 = 00. For blue, we again have to multiply the percentage by 255 to get the numerical value. 50% x 255 is 127 (more or less). Then find the hex value for 127, at the very bottom of the fourth column. So, the blue is 7F. The final step is to write it all together: #59007F, which will get us a fine dark purple, precisely 35% red, 0% green, and 50% blue. |