[Solved] Convert data from const void *data to double


#include <stdio.h>
#include <string.h>

double myfunction(const void *data){
    double v;
    memcpy(&v, data, sizeof(v));
    return v;
}
int main (int argc, char *argv[]) {
    unsigned char data[] = {0x40,0x20,0,0,0,0,0,0};
    int i, len = sizeof(data);

    //reverse data If necessary
    for(i=0;i<len/2;++i){
        unsigned char c = data[i];
        data[i] = data[len -1 -i];
        data[len -1 -i] = c;
    }
    double v;
    v = myfunction(data);
    printf("%f\n", v);//8.000000
    return 0;
}

4

solved Convert data from const void *data to double