How to convert hex to decimal in Actionscript3?

拈花ヽ惹草 提交于 2019-12-23 17:47:11

问题


How to convert hex(in string) to decimal(int) in Actionscript3?


回答1:


Number, int and uint class having toString() method which accept radix as arguments.

radix Specifies the numeric base (from 2 to 36) to use for the number-to-string conversion. If you do not specify the radix parameter, the default value is 10.

you can convert to any base like octal, hex, binary via Number and uint class.

Better 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 to

var hexint:int = int(hex).toString(10); //Decimal conversion

Back to original value :

var decimalStr:String = hexint.toString(16).toUpperCase(); // output : FFFFFF 


来源:https://stackoverflow.com/questions/14659322/how-to-convert-hex-to-decimal-in-actionscript3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!