Deciphering HEX RGBA for MS-filters in CSS

I'm writing styles for a page where I'd like to use rgba colors on the background of some list items. I've used the CSS background property along with rgba(146,138,118,.4) to define my transparent background color.

Now I'm trying to cover my bases with IE support by using the technique of an ms-filter as described in this article. (see heading "...and RGBA for all.")

The trouble is apparently the MS-filter requires you to use some type of hybrid between RGBA and Hex where the alpha transparency value is translated to a number between 00 and FF. See this description page from Microsoft for reference.

So the trouble is I can't figure out how on earth to properly convert my value from RGBA to that hex/rgba hybrid method. Can anybody point me to some good reference material on this? Please don't just give me the correct value - that does me no good outside of that color. I need to understand the how behind it, thanks.


Translating an rgba alpha to the gradient filter format is very simple. It's a mapping from the interval [0, 1] to the interval [0, 255], represented in hex. To do the conversion, then, just multiply by 255 and convert to hex. For example, opacity in rgba(rr, gg, bb, 0.5) ends up as 7F (or 80, if you're rounding up):

0.5 * 255 = 127.5 (base 10)
127 (base 10) = 7F (base 16)

I assume you're not asking about how to convert between base 10 and base 16.

Need Your Help

CakePHP form helper problem with date for editing

cakephp forms helper

I'm quite newbie in CakePHP, I've tried to create a form with form helper on a date field