简体   繁体   中英

C# datatypes in AS3

I'm porting some C# decompression code to AS3, and since it's doing some pretty complex stuff, it's using a range of datatypes such as byte and short . The problem is, AS3 doesn't have those datatypes.

For the most part I can use uint to hold these values. However, at some points, I get a line such as:

length[symbol++] = (short)len;

To my understanding, this means that len must be read and assigned to the length array as a short . So I'm wondering, how would I do this in AS3? I'm guessing perhaps to do:

length[symbol++] = len & 0xFF;

But I'm unsure if this would give a proper result.

So basically, my question is this: how do I make sure to keep the the correct number of bytes when doing this sort of stuff in AS3? Maybe I should use ByteArray s instead?

Depending on reason why cast is in C# code you may or may not need to keep cast in AS3 code. If cast is purely to adjust type to type of elements of length array (ie there is no loss of precision) than you don't need cast. If len can actually be bigger than 0x7FFF you'll need to perform some cast.

I think ByteArray maybe a reasonable option if you need to handle result similar to C# StreamReader , random access may be harder than necessary.

Note that short is 2 bytes long (synonym for System.Int16 ) so to convert to it using bit manipulations you need to do & 0xFFFF . Be also very careful if casting between signed and unsigned types...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM