How to Read Hexadecimal Color Codes

 Hexadecimal, or Hex, color code is often used in programming to select a desired color. The prefix "0x" is used to indicate that the following number is in hexadecimal, although, some codes use the prefix "#" to indicate hexadecimal.

After the prefix, comes six number characters. The first two control the red value. The second two control the green value. And the last two control the blue value. The format looks like this, "0xRRGGBB".

Unlike our base 10 decimal counting system, hexadecimal uses a base 16 counting system. The allowable characters are 0 - 9 and "A" - "F".  The character "A" would have a value of 10, "B" would be 11, and so on until you get to "F", which is equal to 15. To count higher you would add a column and begin the character pattern over again. So the decimal number 16, is hexadecimal 10, and 17 is 11.

This might seem a little confusing at first, but with a little practice, it will begin to feel easy and natural.

To convert hexadecimal to decimal, start by looking at the value of the first character and multiplying it by 16. Then add the value of the second character to the result.

For example, to convert hexadecimal "BC" to decimal we start by taking the value of the first character, "B", which is 11, and multiply it by 16. This gives us a result of 176. Then we add the value of the second character, "C", which is 12. The total result is 188. So hexadecimal "BC" is equal to 11 x 16 + 12, or 188.

To convert decimal to hexadecimal, we start by dividing our decimal value by 16. The whole number portion of our result becomes the value of our first character. Then any remainder value becomes the value of our second character.

For example, to convert decimal 188 to hexadecimal, we divide 188 by 16. This gives us 11.75 as a result. The whole portion of 11.75, or 11, becomes the value of our first character, which is "B". Then we get the remainder. 11 x 16 = 176. 188 - 176 = 12. So, 12 is the remainder, and 12 is the value of our second character, which is "C". Decimal 188 converted to hexadecimal is "BC".

Now we can see how just two characters in hexadecimal can give us a range from 0 to 255 in decimal. Since we have the three primary colors of light, red, green, and blue to mix together, we can create  16,777,216 different color combinations with just 6 hexadecimal characters.


Using hexadecimal to mix different colors of light is pretty simple. The bigger the value, the more of a particular light color there is.

So, hexadecimal 0x000000, has no light value, just total darkness, and produces the color black. While 0xFFFFFF has maximum light value of all colors and produces a bright white.

It is fun to mix different values of colors and see what you end up with, like how green and red will mix to make yellow.


Comments

Popular Posts