i have to read a sequence of bytes,that was written in different ways (writeBite, writeShort and writeMultiByte) and display them has list of HEX byte on video.
My problem is convert the number 1500, i tryed other number and the results was correct…
here is a an example:
var bytes:Array = [];
var ba:ByteArray = new ByteArray();
ba.writeShort(1500);
ba.position = 0;
for (var i=0; i<ba.length; i++)
{
bytes.push(ba.readByte().toString(16));
}
trace(bytes);//5,-24 i'm expetting 5,DC
The method
readBytereads a signed byte (ranges from -128 to 127). The most significant bit defines the sign. In case of numbers greater than127(likeDC) that bit will be1and the number will be seen as a negative number. The two’s complement of the negative byte is used to get the signed value. In case ofDC, which is1101 1100in binary the complement would be0010 0011which is23. A one is added and the value will be regarded as negative, which will give you the-24you are seeing.You should use readUnsignedByte to read values from 0 to 255.