How do I convert hex to decimal in ActionScript3?
Number
, int
and a uint
class that has a method toString()
that takes radix
as arguments.
radix
Specifies the numeric base (2 to 36) that will be used to convert the number to a string. If you do not specify the radix parameter, the default is 10.
you can convert to any base like octal, hexadecimal, binary using the Number and uint class.
The best way
var decimal:int = parseInt("FFFFFF",16);
// output: 16777215
Another way
var hex:String = "0xFFFFFF";
var hexint:int = int(hex);
// output: 16777215
it is equivalent
var hexint:int = int(hex).toString(10);
// Decimal conversion
Return to original value:
var decimalStr:String = hexint.toString(16).toUpperCase(); // output : FFFFFF
source to share