2011-03-10 125 views

回答

1

因此,要获得这样的味道,你可以试试这段代码:

function test(){ 
    var bytes:ByteArray = new ByteArray(); 
    bytes.writeInt(0x00DDAA99); //create my byte array with int 14527129 
    bytes.position = 0;   //move the postion to the start 
    var newInt:int = bytes.readInt(); //read the bytes from starting position 
    trace("new num: "+newInt); //print out the number 
} 

此代码将首先创建一个字节数组,并把一个int进去。这大概是你需要启动代码的地方。这就假定在我设置为0的起始位置之后有4个字节要读取。然后它将字节数组中的4个字节读入队列。请注意,如果您的ByteArray中没有4个字节,或者位置设置不正确,则代码将失败。确保你为这些场景添加了检查。

此代码还假定字节数组是Big Endian。确保如果你有一个来自另一个系统的字节数组,那么你知道int值具有哪个endian-ness。如果需要,更改您的字节数组的末端值。