I am working on an application which interfaces a sensor via the serial port.
The sensor transmits it's data in the IEEE-745 4 byte floating point format. I've read up on the IEEE-745 spec, and I understand that it gives 1 sign bit, 8 exponent bits, and 23 bits for the numeric data.
So I have com with the sensor with the On Com event firing and my 4 byte data coming in nicely. I am able to convert the data to a binary string and display the bits on the screen using the Bitwise library.
Is there a method for converting this binary data into a useful floating point decimal number?
I believe that all Microsoft producs now use IEC 60559:1989 which is the same as the old IEEE-754 standard, although there might be an endian issue with your source. You can try converting a 4 byte array to a Single value using the SingleFromBytes method in my BytesConverter library.
In case you haven't yet found it there is a comprehensive list of Additional Libraries available to registered users.
I cured the endian issue with a for loop. Is there a more elegant method?
Byte 0 is a header. Bytes 1 to 4, 5 to 8, and 9 to 12 are my data.
B4X:
temp() = serial1.InputArray
For i = 1 To 12
sensor(12-i) = temp(i)
Next i
lblA.Text = Round(Bytesconverter.SingleFromBytes(sensor(),8),precision)
lblB.Text = Round(Bytesconverter.SingleFromBytes(sensor(),4) ,precision)
lblC.Text = Round(Bytesconverter.SingleFromBytes(sensor(),0) ,precision)