Domanda

I have a 7 digits hex value like so

id ="0x04 0xDD 0x02 0x82 0x43 0x2F 0x84"

I need to convert this into a proper uint value in actionscript

First i strip the leading '0x's and spaces leaving me with

id= "04DD0282432F84"

Then is it simply a matter of using the built in parseInt method?

my uint value= parseInt(id,radix);

How do you determine what the 2nd radix value should be?

È stato utile?

Soluzione

No, unfortunately its not that simple.

A couple big points of concern you should be aware of:

  1. The "7 digit" (7 byte) hex value is too big for an AS3 uint. uint only supports 32-bit values, and a value like yours is going to need 7 byte * 8 bits/byte = 56 bits. Even Number only handles up to 53-bit integers. You'll need to store it in a pair of uints or approach the problem in a different way.

  2. Since you're receiving the hex bytes separately, they look more like a byte sequence than a number. Are you sure of their byte order? There are a many different ways to store a numerical value as a series of bytes. Some which put the higher values at the beginning, some at the end, and some that can even be more complicated than that.

Ultimately, once you're sure you have the right byte order, you will have to split the first 3-4 bytes from the second 3-4 bytes and parse each one into a separate uint, then keep track of which one represents the big part of the number and which represents the smaller part of the number. Depending on what you need to do with the value, this may make things other things even more complicated (i.e. if you need to do math with the numbers).

If you really do need to go down that road, you may want to use an "arbitrary size" integer implementation, like this one:

http://as3asclublib.googlecode.com/svn-history/r29/trunk/data/BigInt.as

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top