Evaluating the 8-Bit Hexadecimal RBG Color Model

Here’s a fun exercise: how does the computer know what color a 6 digit hex code should represent? In computing, you will often encounter values in base 16, or hexadecimal. In this base system, a single digit can represent values from 0 to 15. An immediate problem would be representing a value greater than 10 in a single digit. Here is where we enlist the alphabet to help us. 1010 is written as A16, 1110 as B16, 1210 as C16, 1310 as D16, 1410 as E16, and 1510 as F16. As the base increases, we enlist more help from the alphabet (and beyond). Read this post on numeric bases if you need a quick primer.

Now, let’s look at the 8-bit hex code color pallet. The RGB model can be represented as (x, y, z), where x, y, and z are integers from 0 to 255. Why 255? To answer that, let’s first think about what 8-bit means. One bit is the smallest unit of storage, on and off, which can be represented as 0 and 1. If we combine 8 of them together, for example 10101010, we will have 8 slots of storage. It’s starting to look awfully like a binary number, and it technically is! We can interpret this 8-bit storage as a binary number, in this case it’s 17010. The maximum binary value we can represent in 8-bit is 111111112, or 25510.

We can further reduce this 8-bit storage into something more manageable: two hexadecimal digits. In the case of 101010102, it’s hexadecimal value is AA16. Finally, we can look at the hex code colors. To display the color white, we set the three primary colors to the max value. The hex code for this is #FFFFFF. We can evaluate #FFFFFF as (FF16,FF16,FF16), or (25510, 25510, 25510). We can see now that this hex code is encoded with the 8-bit value for the three primary colors red, green, and blue, respectively. #FF0000 will be evaluated as (255, 0, 0), which sets the color red to it’s max value, and the rest to 0. What then, will #028482 produce?

 
14
Kudos
 
14
Kudos

Now read this

Resolving Multiple Asynchronous Functions Just Once with Deferred Objects / Promises

I recently came across a piece of legacy code that had to pull data from multiple sources via AJAX requests, then combine it all. A simplified version looks like this: var retrieveOne = function(source, cb) {... Continue →