No it is not all that way so complicated. This runs inside a microcontroller and the message is transmitted by an iphone using the osc protocol (open sound control). It is all very well defined.
Due to compatibillity with a specific iphone app I needed to convert the float. That app only supports the transmission of floats and my application could only handle integers so I needed a conversion.
User Profile
Collapse
-
I thought a float was always 4 bytes long. It would also be possible to test the length of val but the result is only 4 bytes long.
memcpy(&val,&re sult, sizeof val);
The 4 bytes in the buffer came from an utp buffer.Leave a comment:
-
ah found the result:
Code:// read an unsigned long int from 4 bytes in buffer, // starting at offset, MSB first float readfloat(byte * buffer, int offset) { float val=0; unsigned long result=0; result |= ((unsigned long)(buffer[offset]) << 0x18); result |= ((unsigned long)(buffer[offset+1]) << 0x10); result |= ((unsigned long)(buffer[offset+2])
Leave a comment:
-
How to convert 4 byte's to float?
I'm adapting a piece of code. The original code takes 4 bytes and convert that to an integer.
In my case this memory contains a float and I want the function to return a float.
Here is the original code:
Code:// read an unsigned long int from 4 bytes in buffer, // starting at offset, MSB first unsigned long readLongInt(byte * buffer, int offset) { unsigned long result=0; result |= ((unsigned
No activity results to display
Show More
Leave a comment: