0
votes

If I have the array of byte :

byte [] a=new byte [4]{0,0,0,1};

Is this sequence of data 0001 is Little endian or big endian? And when I need to reverse array

with Little endian or big endian?

The architecture of my computer is Littleendian

1
If your desired 32-bit value is 1, it's stored as big endian.Joachim Isaksson
i must make reverse for array to store result as big endian=1??user2839704
The question doesn't make sense, bytes don't have an endian order. Only value type values of a type that requires more than a byte for storage can be affected, a byte[] is unambiguous. You only ever have an issue you try to convert the byte[] to another type with BitConverter. Given the scarcity of big-endian machines today, you'd better start with {1, 0, 0, 0} if an int value of 1 is intended.Hans Passant

1 Answers

0
votes

That would be in little-endian representation, as the smallest component is at the end.

You can use the BitConverter.IsLittleEndian property to dynamically find out the endianess of the system that the program is running on:

if (!BitConverter.IsLittleEndian) {
  Array.Reverse(a);
}