开发者

byte array to double

开发者 https://www.devze.com 2023-01-14 00:07 出处:网络
I have a four byte char array and I w开发者_StackOverflowant to convert it to double. How can I achieve this in C.float and double are so closely related in C that an explicit conversion is probably n

I have a four byte char array and I w开发者_StackOverflowant to convert it to double. How can I achieve this in C.


float and double are so closely related in C that an explicit conversion is probably not needed. However, it would be necessary for transmission to another system, or to match a data format specification. This will do what you ask:

union {
    char   c [4];
    float  f;
} x;
double d;

memcpy (x.c, character_source, sizeof x.c);
d = x.f;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号