المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : I have a float in a binary file ( 0x00, 0x00, 0x06, 0x8B ) (1675), on a Windows Machi



C# Programming
05-05-2009, 04:13 AM
I have a float in a binary file ( 0x00, 0x00, 0x06, 0x8B ) (1675), on a Windows Machine, How do I read it in from a binary file in c#?
(The file was written big endian, I am trying to read it in on a little endian computer)
Currently I
{
BinaryReader BR = new BinaryReader(File.Open("test.bin", FileMode.Open), Encoding.BigEndianUnicode);
byte[] arr = BR.ReadBytes(4);
BR.Close();
float altmsl = GetFloat(arr, 0);
}
static float GetFloat(byte[] fullpacket, int startindex)
{
byte[] intarr = new byte[4];
Array.Copy(fullpacket, startindex, intarr, 0, 4);

Array.Reverse(intarr);
return BitConverter.ToSingle(intarr, 0);
}

and this returns a number to e-22
double, and int works just fine