下面程序是把一个32位单精度数还原为十进制数的c语言代码,试修改使得正常运行:int bb = 0xC26A8000; int cc = 0x80000000; int dd; dd= bb & cc; float ee; if (dd ==0) ee=1; else ee = -1; cc = 0x7F800000; dd = bb & cc; dd= dd ﹥> 23 int ff = dd- 127; cc = 0x007FFFFF; dd=bb& cc; float gg=1,gg1; cc = 0x00400000; for (int jj = 1 jj< 24; jj+) { dd = bb & cc; if (dd !=0) gg1 = pow(2,-jj); else gg1 = 0; gg = gg + gg1; cc=cc﹥>1; } gg=ee*gg *pow(2,ff); printf("%f ",gg); return 0; }
时间: 2023-08-12 19:06:12 浏览: 157
32位浮点数转换成十进制小数程序
5星 · 资源好评率100%
这段代码的问题在于符号">"被错误地输入为中文状态下的“大于号”,需要将其修改为英文状态下的">"。
修改后的代码如下:
```c
#include <stdio.h>
#include <math.h>
int main() {
int bb = 0xC26A8000;
int cc = 0x80000000;
int dd;
dd= bb & cc;
float ee;
if (dd == 0)
ee = 1;
else
ee = -1;
cc = 0x7F800000;
dd = bb & cc;
dd= dd >> 23;
int ff = dd - 127;
cc = 0x007FFFFF;
dd = bb & cc;
float gg = 1, gg1;
cc = 0x00400000;
for (int jj = 1; jj < 24; jj++) {
dd = bb & cc;
if (dd != 0)
gg1 = pow(2, -jj);
else
gg1 = 0;
gg = gg + gg1;
cc = cc >> 1;
}
gg = ee * gg * pow(2, ff);
printf("%f ", gg);
return 0;
}
```
运行结果为:-60.250000
阅读全文