float型转换成unsigned char*型,该怎么处理

如题所述

------解决方案--------------------探讨C/C++ code_fcvt()_gcvt()------解决方案-------------------- 通常要从串口发送float的话就要用到:#define IEEEbyte(float,which) (((IEEE*)&float)->B4.byte##which)typedef struct{unsigned char byte1;unsigned char byte2;unsigned char byte3;unsigned char byte4;}Bytes4;typedef union{Bytes4 B4;float df;}IEEE;其实就是把这个float看成4个bytes;用时:void main(){float a;int x;unsigned char byte1,byte2,byte3,byte4;// a=-4.123457;//C0 83 F3 5Ca= 4.123457;//40 83 F3 5Cbyte1=IEEEbyte(a,0);byte2=IEEEbyte(a,1);byte3=IEEEbyte(a,2);byte4=IEEEbyte(a,3);//发送这4个BYTES 。。。}------解决方案--------------------探讨通常要从串口发送float的话就要用到:
温馨提示:答案为网友推荐,仅供参考