C++ float与char[4]互转
#include <stdio.h>
// 首先定义C的共同体
union MyUnion
{
float f;
char ch[4];
} mUion;
int main(void)
{
// 使用
MyUnion my;
//my.f = 15.52;
my.ch[0] = 0xec;
my.ch[1] = 0x51;
my.ch[2] = 0x78;
my.ch[3] = 0x41;
for (int i = 0; i < 4; i++)
{
printf("%x\n", my.ch[i]);
}
printf("%f,,%f\n", my.f, (float&)my.ch);
return 0;
}
本文来自博客园,作者:一夜梦想,转载请注明原文链接:https://www.cnblogs.com/caiyingyong/p/16925050.html

浙公网安备 33010602011771号