user3535716
user3535716

Reputation: 255

How to set the endian of a byte array in c#

I've got some java codes like this:

   ByteBuffer buffer = ByteBuffer.allocate(length * 2);
   buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);
    for (short s : data)
      buffer.putShort(s);

How to convert it to C# code? basically, I don't know the how to work

  buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);

out in C#.

Any help is appreciate!

Upvotes: 1

Views: 1150

Answers (1)

Tom Maher
Tom Maher

Reputation: 2054

Probably a good place to start looking would be the msdn library docs specifically the System.Convert class can be used to convert value types to raw bytes and back again.

It looks like this question may help you as well:

Is .NET BinaryReader always little-endian, even on big-endian systems?

Upvotes: 1

Related Questions