link

Hi there,

I have written this piece of code in C# so that it reads binary from a file at a given offset, however how would I go about storing the bytes in an array so that I could convert from Little Endian to Big Endian?

Here's my code ...

public static class MyGlobals
{
public static string longitudeHex = null;
public static double longitudeDec;
public static double longitude;
public static string LatitudeHex = null;
public static double LatitudeDec;
public static double Latitude;
}
public int ConvertByteArrayToInteger(byte[] bInteger)
{
if (BitConverter.IsLittleEndian == true)
Array.Reverse(bInteger);

return BitConverter.ToInt32(bInteger, 0);
}

public void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
BinaryReader br = new BinaryReader(File.OpenRead(openFileDialog1.FileName),System.Text.Encoding.BigEndianUnicode);

// Read in the Longitude
for (int i = 0x1E; i <= 0x21; i++)
{
br.BaseStream.Position = i;
MyGlobals.longitudeHex += br.ReadByte().ToString("X2");
MyGlobals.longitude = Convert.ToInt64(MyGlobals.longitudeHex, 16);

}

MyGlobals.longitudeDec = MyGlobals.longitude / 100000;
longitude_txt.Text = Convert.ToString(MyGlobals.longitudeDec);

}