C# little endian or big endian?

C# itself doesn’t define the endianness. Whenever you convert to bytes, however, you’re making a choice. The BitConverter class has an IsLittleEndian field to tell you how it will behave, but it doesn’t give the choice. The same goes for BinaryReader/BinaryWriter.

My MiscUtil library has an EndianBitConverter class which allows you to define the endianness; there are similar equivalents for BinaryReader/Writer. No online usage guide I’m afraid, but they’re trivial 🙂

(EndianBitConverter also has a piece of functionality which isn’t present in the normal BitConverter, which is to do conversions in-place in a byte array.)

Leave a Comment