When specifying colors in the computer world, we often break colors down to combinations of Red, Green and Blue. While other color schemes are also used (such as CMYK -- Cyan, Magenta, Yellow and blacK), the RGB scheme is the one most used in Web development.
Each individual element of an RGB (red-green-blue) color combination can be represented by a number. In graphic design, each element can be represented by a Base-10 (decimal) value between 0 and 255. Consider the following table:
| Red | Green | Blue | COLOR |
| 255 | 0 | 0 | RED |
| 0 | 255 | 0 | GREEN |
| 0 | 0 | 255 | BLUE |
| 255 | 255 | 255 | WHITE |
| 0 | 0 | 0 | BLACK |
| 128 | 128 | 128 | GRAY |
As you can see from the table, each color is represented by an array of three values. Each value can be between zero and 255. When specifying a color using Base-10, it common to use the expression RR, GG, BB. For instance, the color Yellow can be represented by 255, 255, 0 (where the RED value is 255, the GREEN value is 255, and the BLUE value is 0).
In the graphic design, it is common to specify RGB color combinations using Base-10 numbers and Base-10 can also be used to specify Web colors. However, it is much more common to specify Web colors using a Base-16 (hexadecimal) numbering system.
Hexadecimal color representations are also R-G-B combinations. Using hexadecimal, each element of an RGB combination can take a value between 00 and FF. Huh? FF? I thought we were talking about numbers? Well, we are. However, remember that hexadecimal is a Base-16 numbering system. In a decimal numbering system, numbers start repeating after the 10th digit, or 9 (0,1,2,3,4,5,6,7,8,9, 10,11, ...). In a hexadecimal numbering system, numbers repeat after the 16th digit, or 0F (00,01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F, 10,11, ...). Notice each digit in hexadecimal is represented by two characters. Let's take a look at the color table from before, but this time using hexadecimal values:
| Red | Green | Blue | COLOR |
| FF | 00 | 00 | RED |
| 00 | FF | 00 | GREEN |
| 00 | 00 | FF | BLUE |
| FF | FF | FF | WHITE |
| 00 | 00 | 00 | BLACK |
| 80 | 80 | 80 | GRAY |
When specifying colors using a hexadecimal numbering scheme, we use the expressiong RRGGBB. For example the color Yellow is expressed FFFF00. Usually, the hexadecimal expression will be preceded by the pound symbol -- #FFFF00.
As many of us have already done some work in graphic design, we may have favorite colors that we would like to use in Web pages. To do this, we need to convert colors specified in decimal values to hexadecimal values. We must first remember that the hexadecimal numbering system is Base-16 and the decimal numbering system is Base-10. Let's first take a look at hexadecimal equivalents of decimal numbers:
| Decimal/Hexadecimal Equivalents | ||||||||
| DEC | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| HEX | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 |
| DEC | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| HEX | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F |
Okay, so now we have an equivalent chart for the decimal values zero through fifteen. But what about converting decimal values greater than fifteen? To convert the decimal value to hexadecimal, we need to divide the decimal value by sixteen. We refer to the equivalency chart and then convert both the quotient and the remainder. Then we concatonate ("string together") the two numbers.
Let's take a look at an example. Suppose we were given the Base-10 RGB expression for the color firebrick, which is 178, 34, 34. How should we convert this expression to a hexadecimal expression?
The following table summarizes the conversion process:
|
Step One:
Decimal RGB Values |
Step Two:
Divide by 16 |
Step Three:
Convert to Hexadecimal |
Step Four:
Concatonate the RGB Values |
||||
| Division | Q | R | Q | R | #B22222 | ||
| RED | 178 | 178/16 | 11 | 2 | B | 2 | |
| GREEN | 34 | 34/16 | 2 | 2 | 2 | 2 | |
| BLUE | 34 | 34/16 | 2 | 2 | 2 | 2 | |
Let's try another conversion. This time let's try the Base-10 RGB combination 98, 13, 255, which is a color
a little darker than Royal Blue:
|
Step One:
Decimal RGB Values |
Step Two:
Divide by 16 |
Step Three:
Convert to Hexadecimal |
Step Four:
Concatonate the RGB Values |
||||
| Division | Q | R | Q | R | #620DFF | ||
| RED | 98 | 98/16 | 6 | 2 | 6 | 2 | |
| GREEN | 13 | 13/16 | 0 | 13 | 0 | D | |
| BLUE | 255 | 255/16 | 15 | 15 | F | F | |
Try a few conversions on your own. Click the answer link for each
color at the bottom of each table for answers:
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||