A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

123lll

初级黑马

  • 黑马币:6

  • 帖子:2

  • 精华:0

© 123lll 初级黑马   /  2020-9-28 21:31  /  1325 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1、定义一个浮点型变量a=11.1234 作为发送端,它向接收端发送的是16进制代码 72 F9 31 41
2、在接收端编写程序
int temp;
int count = start + 0;
temp =(unsigned char)buf[count + 3] << 24 | (unsigned char)buf[count + 2] << 16 | (unsigned char)buf[count + 1] << 8 | (unsigned char)buf[count + 0] << 0;
a = (float)&temp;
把发送端与接收端通信连接后,接收端会输出a=11.1234
/***************************************************/
但是如果发送端发送一个双精度浮点型变量b=11.123456789作为发送端,它向接收端发送的是16进制代码C7 72 6E BA 35 3F 26 40
在接收端编写程序
int temp;
int count = start + 0;
temp =(unsigned char)buf[count + 3] << 24 | (unsigned char)buf[count + 2] << 16 | (unsigned char)buf[count + 1] << 8 | (unsigned char)buf[count + 0] << 0;
b = (double)&temp;
把发送端与接收端通信连接后,接收端会输出b=-9.25596e+061并没有输出想要的值
/**********************************************************/
/**********************************************************/
float四个字节 double八个字节
按照八个字节解码进行编写:
temp =(unsigned char)buf[count + 7] << 56 | (unsigned char)buf[count + 6] << 48 |
                (unsigned char)buf[count + 5] << 40 | (unsigned char)buf[count + 4] << 32 |
                (unsigned char)buf[count + 3] << 24 | (unsigned char)buf[count + 2] << 16 |
                (unsigned char)buf[count + 1] << 8 | (unsigned char)buf[count + 0] << 0;还是不对
如何修改接收端的解码程序,可以输出一个双精度浮点数?
希望大佬们可以帮助,交流一下,关于我这个内容在网上找了好久也没有找到,修改的内容应该是temp的解码程序,希望大佬们能帮忙指点一下!!

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马