CamWorld:  Random Thoughts - Web Design - New Media

 

From the WebDesign-L Mailing List

[One of the best explanations of how hexidecimal colors work I've ever read.]

From: SAVEL, CRAIG [SMTP:CSAVEL@popcouncil.org]
Sent: Thursday, October 15, 1998 11:04 AM
To: tari@centtel.com
Cc: webdesign-l@hesketh.com
Subject: RGB equiv of hex

The original question

Now if it was a regular hex number, I could figure it out, but I have no idea how to convert it. I'd love to know though, if someone could tell me how to calculate the RGB of one of the 'evil' hex colours.

The answer

Tari, a little background, and an example, for future reference:

In Hexadecimal (a fancy way of saying base-16), the first character of a value pair represents how many times sixteen occurs in the value. The second character in a value pair represents a number between zero and fifteen. In order to express values between ten and sixteen using only one character, hexadecimal resorts to letters (a-f), as follows:

A=10, B=11, C=12, D=13, E=14, F=15 [There is no character for sixteen, because to express sixteen sixteens, you would simply move over to the next number slot to the left, and begin with one (similar to, instead of writing ten tens, you write one hundred).]

Confused? I'm beginning to confuse myself, I'm afraid.

Let's take an Example:34c9af

This is a set of three values 34, c9, and f3. Let's start with the R value (34). The character 4, being in the first value slot (first on the right) represents iterations of ONES, and thus should be interpreted as, simply, four times 1 (which equals four). Put this number to the side. The character (3), in the second value slot represents iterations of SIXTEENS. So multiply 3 by sixteen, and you get = fortyeight. Now, simply add the previous four to this forty-eight, and you get fifty two. 34 in hexadecimal is 52 is decimal notation.

So, green RGB value (c2) will be 2 x ONE, plus C times sixteen. C is hex for twelve, so its actually twelve times sixteen. c2 can be written formulaicly as (C x 16)+(2 x 1), which equals 194 in decimal. Analogously, the number (let's say 54) in decimal could be formulaicly expressed (5 x 10)+(4 x 1).

Now, the Blue value (af): We can write that thus: (A x 16) + (F x 1). F is hex for 15(decimal), and A is hex for 10(decimal). So, let's substitute decimal values for hex letters, and write (10 x 16) + (15 x 1). This equals 175 in decimal.

So, 34c9af in hex is 52, 194, 175 in RGB.

R = red
G = green
B = blue

©1997-98 Cameron Barrett