字节数组翻番 [英] byte array to double

查看:137
本文介绍了字节数组翻番的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个4字节字符数组,我想将它转化成一倍。我怎样才能在C ++中实现这一点。

I have a four byte char array and I want to convert it to double. How can I achieve this in C.

推荐答案

浮动双击是如此密切相关在 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;

这篇关于字节数组翻番的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆