浮点型和十六进制之间的转换

论坛 期权论坛 脚本     
匿名技术用户   2020-12-22 19:32   855   0
  1. #include "stdafx.h"
  2. #include <process.h>
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5. // 将十六进制转换为float形式
  6. unsigned char pMem[] = {0x66,0xE6,0xF0,0x42};
  7. float *p = (float*)pMem;
  8. printf("%g\r\n",*p);
  9. // 将float转换为16进制
  10. float a=120.45f;
  11. unsigned char * b = (unsigned char*)&a;
  12. for(int i = 0; i<4; i++)
  13. printf("0x%2X,", b[i]);
  14. system("pause");
  15. return 0;
  16. }
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP