Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

BitPattern to Float


artmann Jul 23, 2009 09:10 PM

hi,
i am reading a ASCII string from a rs232-device via one of the com-ports of a CR1000.
Embedded in the string is a stream of (normalized) 4-Byte single precision floating-point numbers(IEEE 754-1985).
These show up as the ASCII equivalent of the bit-pattern.
While its not too difficult to parse the single characters and insert them according endianness into a LONG for holding the pattern,
i am not sure if the actual "conversion" to FLOAT _must_ be done manually with some more bit-fiddling.
As CRBasic provides some dynamic casting, i wonder if there is some syntactic sugar or a function available to get this done.
Maybe there exists a much simpler way i am to blind to see...

* Last updated by: artmann on 7/23/2009 @ 3:16 PM *


aps Jul 24, 2009 10:11 AM

IF the values are in the string as 4 bytes, then have a look at the Movebytes command, and the example, that can be used to move four bytes out of a string directly into a float in the logger (which also used IEE754 single precision FP). The example shows how to reverse the byte order depending on which way they are arranged in the string.

IF each bit is in a single ascii character then you will need to do a bit more processing to perhaps build them into a long, as you say, before moving them into the float.

* Last updated by: aps on 7/24/2009 @ 4:57 AM *


artmann Jul 24, 2009 10:32 AM

hi,
this is exactly what i was searching for.
haven't tried it by now, but this looks great.

thanks a lot!

Log in or register to post/reply in the forum.