Code Snippet: Extract ARGB Bitwise

The following code will extract the four 8 bit channels from a 32 bit color.

package net.avdw.color
{
	/**
	 * Extract four channels (a, r, g, b) from a 32 bit color.
	 *
	 * @param	color	A 32 bit color.
	 * @return	An object with properties a, r, g, b
	 */
	public function extractARGB(color:uint):Object
	{
		return {a: color >> 24 & 0xFF, r: color >> 16 & 0xFF, g: color >> 8 & 0xFF, b: color & 0xFF};
	}
}

Here is an example of this method in action.

var ec:Object = extractARGB(0xEECCFF);
trace(ec.a.toString(16), ec.r.toString(16), ec.g.toString(16), ec.b.toString(16));
// prints 0 ee cc ff