By default, the BinaryWriter class writes int values with the least significant digits to the left (for example, (int) 6 becomes 06 00 00 00 when the resulting file is viewed in a hex editor). I need low digits on the right (e.g. 00 00 00 06).
How do I achieve this?
EDIT: Thank you, guard, for giving me the name of what I was looking for. I edited the title and tags to make them easier to find.
Jon Skeet EndianBitConverter , . / , . , ; -p
int i = 6; byte[] raw = new byte[4] { (byte)(i >> 24), (byte)(i >> 16), (byte)(i >> 8), (byte)(i)};
, : EndianBit *. : P
" " ( "Endianness" ). endian. , #, , BinaryWritter.
System.BitConverter.IsLittleEndian. , BinaryWriter endian .
- , System.Net.IPAddress.HostToNetworkOrder().
, , , "" , "" , , .
, , .
, , . - :
Byte[] bytes = BitConverter.GetBytes(number); Array.Reverse(bytes); // Then, to write the values you use writer.Write(bytes);
, connect ticket BinaryReder/Writer Bigendian . .