Hi,
Can anyone tell me how to open a binary file and read as either little or big endian using c#.
Any website or sample code that i can refer to???
Thanks in advance.
Printable View
Hi,
Can anyone tell me how to open a binary file and read as either little or big endian using c#.
Any website or sample code that i can refer to???
Thanks in advance.
I think you will have to manage it by yourself. You could read the file into a byte[] then convert it to whatever you need; short[] or integer[].
This method produce an integer from a byte array that contains an integer formatted in big endian. The method assumes a 4 bytes array.
public int ConvertByteArrayToInteger(byte[] bInteger)
{
if (BitConverter.IsLittleEndian == true)
Array.Reverse(bInteger);
return BitConverter.ToInt32(bInteger, 0);
}
I forgot...
To read a binary file, use the System.IO.BinaryReader class. Very simple.
why would it's endianness be different than everything else?
I had to read raw database files that were produced on a Palm and the type of CPU uses by this system stores variables in the big-endian format.