I am trying to read a binary file with the BinaryReader class, and I need to read it in as blocks of UInt32, and then do some bit shifting etc. afterwords.
But, for some reason bit order is reversed when I use the ReadUInt32 method.
If I for example have a file where the first four bytes looks like this in hex, 0x12345678
, they end up like this after being read by ReadUInt32: 0x78563412
.
If I use the ReadBytes(4) method, I get the expected array:
[0x00000000] 0x12 byte
[0x00000001] 0x34 byte
[0x00000002] 0x56 byte
[0x00000003] 0x78 byte
Why is this? Is it just the way .net represents uints in memory? Is it the same across the different platforms (I am running 64bit Windows 7, .net 3.5 sp1)?
Edit: Thanks for the great feedback guys! Once again the stackoverflow community comes to the rescure :)