Hexadecimal arithmetic in Google

Did you know that you can do hexadecimal arithmetic in Google? I didn’t, but I knew that Google’s calculator feature would often just do ‘the right thing’, so I decided to try it out.

I wanted to use the Google Chart API to create a grouped bar chart. I wanted each of the four bars in the group to be a different shade of blue. So, I picked two shades of blue to be my ‘book ends’. These book end colors were:

  • c6d9fd
  • 0000f9

Notice that the blue portion of those colors, ‘f9’, is the same. So, I wanted to find two shades of blue that were equally between those bookends. I needed to find the difference between c8d9 and 0000, and then divide that by three. Well, the fact that one of these book end numbers is zero makes this a bit easier:

c8d9 / 3

But how do I do this calculation on my handy desktop calculator? It only operates in base-10. As it turns out, you can get Google to do this calculation for you:

0xc6d9 / 3 Google Screenshot

I couldn’t get it to give me that result in hexadecimal, but at least now I know that 0xc8d9 / 3 = 16,968.3333 in decimal. Now, I just needed to find the two points that are in the middle of my two bookends. So, I need to calculate (in Google terms):

(0xc6d9 - 16968) in hex
(0xc6d9 - (16968 * 2)) in hex

In the end, I found my four colors:

  • c6d9fd
  • 8491f9
  • 4249f9
  • 0000f9

And then, I used these colors in my chart, and got a nice gradient effect in the bars:

Bar Chart Final Product

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment