1 可以通过union来转换
2 可以通过这种方式来转换
#include <cstdio>
int main()
{
float f=1.1234;
float f1=0;
int b=0;
b = *(int*)&f;
printf("%d\n",b);
f1 = *(float*)&b;
printf("%f\n",f1);
}
输出结果是可以写一个带参数的宏
#include <cstdio>
#define _2INT(TMP) *(int*)&TMP
#define _2FLOAT(TMP) *(float*)&TMP
int main()
{
float f=1.1234;
float f1=0;
int b=0;
b = *(int*)&f;
printf("%d\n",b);
f1 = *(float*)&b;
printf("%f\n",f1);
b = _2INT(f);
printf("%d\n",b);
f1 = _2FLOAT(b);
printf("%f\n",f1);
}