-
Recent Posts
Recent Comments
Categories
Tags
apache beer beernutz bigbrother boston bottle buttons cartography computers conditioning css database deadlock draft economics firebug freedom gmail hexadecimal homebrewing html java javascript maps mbta mustache outlook performance podcasts politics productivity programming quality random recipe sea stackoverflow subway surveillance taxes testing tricks tv web wedding-
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:
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 / 3But 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:
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 hexIn the end, I found my four colors:
And then, I used these colors in my chart, and got a nice gradient effect in the bars: