Internet Explorer 6 is not supported.
Upgrade to view this site.

Blog Archive

Results for the blog tag utilites.

Hex to Unsigned Integer and Back Again

Here are some quick one line wonders. From reading some stuff here and there I was able to fashion 2 functions for handling the conversion between hex strings and unsigned integers. Most of the time a uint is asked for when it comes to color, but some things like the StyleSheet object asks for a string value of a hex color like you would use in CSS.

I guess these function names got a little long, but they are very descriptive to what they do, and when you use Flex with it’s completion function name brevity isn’t as much of an issue as it is with Flash.

1
2
3
4
5
6
7
8
9
10
11
12
function hexColorToUnsignedInteger(hex:String):uint
{
	return uint("0x" + hex.split("#")[1]);
}
 
function unsignedIntegerToHexColor(num:uint):String
{
	return String("#" + (num.toString(16).toUpperCase()));
}
 
trace(hexColorToUnsignedInteger("#FF0000"));
trace(unsignedIntegerToHexColor(0xFF0000));