On Sun, 22 Apr 2007 22:13:03 +0300, "Yasin Cepeci" <ce****@gmail.com>
wrote:
>I ve get float data from serial port. I ve taken it in the form of hex by
modbus protocol. I know it is float but I couldnt convert it
there is a few sample data below;
B3 33 43 34 = 180.699997
33 33 43 33 = 179.199997
B3 33 43 34= 180.699997
CC CD 43 33=179.800003
But how can I found it. I couldnt resolve it.
It looks as if you just need to reorder the bytes and cast to float.
180.70000 -33-B3-34-43
179.20000 -33-33-33-43
180.70000 -33-B3-34-43
179.80000 -CD-CC-33-43
Code used:
static void Main() {
float[] test = { 180.699997F,
179.199997F,
180.699997F,
179.800003F };
foreach (float ff in test) {
byte[] bytes = BitConverter.GetBytes(ff);
Console.WriteLine("{0:F5} -{1}",
ff, BitConverter.ToString(bytes));
}
} // end Main()
rossum