trex005 trex005 - 2 months ago 8x
ActionScript Question

Actionscript littleEndian to c#

I inherited a proprietary file parser written in actionscript. I am converting it to c# and I'm at a loss as to how to handle the following step.

public function transform(input:ByteArray) : ByteArray
var output:ByteArray = new ByteArray();
output.endian = "littleEndian";
return output;

I've been trying to read up on endianness, and the only thing I can fathom that this would do is reverse the order of bytes. Is that correct? If so, how would I replicate that in c#?


The code will copy the data in input to output unmodified (since bytes don't have endianness) and afterwards all read operations from the returned ByteArray will use little endian.

On little endian platforms (x86 for example and nowadays pretty much all OSes ARMs as far as I know) .NET will by default use little endian if you use BinaryReader for example.

So basically that code in .NET would be to create a MemoryStream of the bytes and then a BinaryReader for that stream.

You can check whether the platform on which your C# code is running on is little or big endian by using BitConverter.IsLittleEndian