Convert Hex To/From int/uint in As3

      No Comments on Convert Hex To/From int/uint in As3

In as3 it might be a simple and convenient way to store all sort of variables as String. When you have to store or transfer intergers (int or uint) it’s very easy to keep them in hexadecimal values. For example an array of integer can be stored in a comma separated string or in a string of values of the same length. For the first case everything is trivial. In the second case we have to take care when we serialize the integer values to prefix them with zeros so all of them will have the same length.

All we have to do to transform an integer to a hex string is to use toString() method.

Then to do get the int from a string we can use the parseInt global function:

If we want to have the same dimension for all of them we should use some helper functions to prefix the strings with zeros when necessary. The following example transforms the integers in strings of length of 3(min 000, max FFF).

Leave a Reply

Your email address will not be published. Required fields are marked *