四字节与float转换

来源:互联网 发布:功夫熊猫中的师傅知乎 编辑:程序博客网 时间:2024/04/29 15:00
    
/////////char  to  float
     char sBuf[4];
     sBuf[0]=0x00;
     sBuf[1]=0x00;
     sBuf[2]=0x48;
     sBuf[3]=0x42;
     float a= *(float*)(sBuf);
///////// float to char
     float wTemp=50;
      char sBuf1[4];
      char* temp;
      memset(sBuf1,0,sizeof(sBuf1));
      temp=(char*)(&wTemp);
      sBuf1[0] = temp[0] ;
      sBuf1[1] = temp[1];
      sBuf1[2] = temp[2];
      sBuf1[3] = temp[3];
0 0
原创粉丝点击