How do I take four received data bytes and assemble them into a floating-point number?
Right now I have the bytes stored in an array, which would be, received_data[1] ... received_data[4]. I would like to store these four bytes as a single 32-bit single precision float.
-Thanks
I'm actually receiving a packet with 19 bytes in it and assembling two sets of four bytes to make two floating-point numbers. So received_data[1] to received_data[4] is one float, and received_data[5] to received_data[8] is the other...
*UPDATE:** More Info...
The first bit, or the sign bit of the float, is the seventh bit the the first byte, here's what I did to check...
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
if( CHECK_BIT(received_data[1], 7)) //set or clear LED2
{LATAbits.LATA2=1;}else{LATAbits.LATA2=0;}
if( CHECK_BIT(received_data[5], 7)) //set or clear LED3
{LATAbits.LATA3=1;}else{LATAbits.LATA3=0;}
I then checked this by sending alternating positive and negative numbers from my data source, which should have changed the LED's accordingly and it worked.
As long as all that holds true, that means the bytes are in the right order, but they are stored little-endian, correct? Will this be stored into the float in the right order? I haven't had any luck parsing the bytes and reading it as a float yet...
If anyone has any experience with it, I'm using the C18 MPLAB IDE compiler.
FINAL UPDATE:
I have my application running! Just some minor bug fixes now!
THANKS!
Thanks for all the help guys! I'm new to stackoverflow, but this community on here is truly awesome! And a tool like this is truly priceless! I can not even begin to tell you how much time and frustration you have all saved me!