AS3 ByteArray 短读
我必须读取以不同方式(writeBite、writeShort 和 writeMultiByte)写入的字节序列,并在视频上显示它们的十六进制字节列表。 我的问题是转换数字 1500,我尝试了其他数字,结果是正确的...... 这是一个例子:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
readByte 方法读取有符号字节(范围从 -128 到 127)。最高有效位定义符号。如果数字大于
127
(如DC
),该位将为1
并且该数字将被视为负数。负字节的二进制补码用于获取有符号值。对于DC
(二进制为1101 1100
),补码将为0010 0011
,即23
。添加 1 后,该值将被视为负数,这将为您提供您所看到的-24
。您应该使用 readUnsignedByte 读取 0 到 255 之间的值。
The method
readByte
reads 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 be1
and 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 1100
in binary the complement would be0010 0011
which is23
. A one is added and the value will be regarded as negative, which will give you the-24
you are seeing.You should use readUnsignedByte to read values from 0 to 255.
由于 AS3 中没有真正的 Byte 类型,因此
readByte()
返回 int。你可以尝试这个:As there is no real Byte type in AS3,
readByte()
returns an int. You can try this instead: