void ExpIEEE754(void)
{
UINT8 j,jie,*p1,*p2;
// static UINT8 cnt=0;
int recv,wei;
union {
UINT8 buf[4];
int Data;
}tmp;
if (gsPtlBuf[3].wDataLen != 7)
{
printf("690Frame Len Err! %d\n",gsPtlBuf[3].wDataLen);
return;
}
p1 = &gsPtlBuf[3].cBuf[0]; //源数据
p2 = &gsPtlBuf[3].cBuf[3]; //转换后的数据
for (j=0; j<3; j++)
p1[j] = ((p1[j]>>4)*10) + (p1[j]&0x0f);
recv = ((*p1)*10000) + ((*(p1+1))*100) + (*(p1+2)); //转换为16进制数
wei = recv; //尾数。故意不舍弃最高位
for (jie=0; jie<24; jie++) //阶数
{
recv >>= 1;
if (recv == 0)
break;
}
// if ((wei&0x7ffff) != 0)
{
for (j=0; j<22; j++)
{
if ((wei & (1<<23)) == 0) //补满23位
wei <<= 1;
else
break;
}
}
tmp.Data = ((jie+127)<<23) | (wei&0x7fffff);
for (j=0; j<4; j++)
{
if (tmp.buf[3-j] != *(p2+j))
{
printf("JieShu:%d\n",jie);
printf("WeiShu|0x800000=%x\n",wei);
printf("his data:%2x %2x %2x %2x\n",*p2,*(p2+1),*(p2+2),*(p2+3));
printf("my data: %08x\n",tmp.Data);
break;
}
}
if (j >= 4)
printf("Converse Succ!\n");
}
文章评论(0条评论)
登录后参与讨论