I want to get data as a double so after that i send the data as uint8_t array. So I determined 2 steps.Steps;
1-First Step :Double to uint8_t
#include <stdint.h> #include <stdio.h> #include <string.h> void float2Bytes(double val,uint8_t* bytes_array); int main(void) { double b=1690.000000; uint8_t message[1024]; float2Bytes(b,&message[0]); int ii; for (ii=0; ii<8; ii++) printf ("byteS %d is %02x\n", ii, message[ii]); return 0; } void float2Bytes(double val,uint8_t* bytes_array){ // Create union of shared memory space union { double double_variable; uint8_t temp_array[8]; } u; // Overite bytes of union with float variable u.double_variable = val; // Assign bytes to input array memcpy(bytes_array, u.temp_array, 8); } 2-Second Step : uint8_t array to Double
Can you advise at the this stages ? How can I do ? And can you examine at the first stage whether there are errors or not. ?
Thank you.
doublememberdouble2Bytesand notfloat2Bytes