IEEE754 浮点数
1.阅读IEEE754浮点数
A,阶码是用移码表示的,这里会有一个127的偏移量,它的127相当于0,小于127时为负,大于127时为正,比如:10000001表示指数为129-127=2,表示真值为2^2,而01111110则表示2^(-1).
B, 尾数全都是小数点后面的数,
C, 但尾数中省略了一个1,因此尾数全为0时,也是1.0...00;
D,当尾数的值不为0时,尾数的最高有效位应为1,这称为浮点数的规格化表示
2.把十进制数5.75,161.875,-0.0234375 转化为单精度浮点数的二进制格式
自己转化的结果
01000000101110000000000000000000
01000011001000011110000000000000
10111100110000000000000000000000
浮点数转化工具的结果
使用python编程完成转化。
参考资料:
1.Python实现十进制小数转IEEE754单精度浮点数转换
2.python之def函数 - derezzed - 博客园
3.你必须理解的三大软件原则1_DRY
代码链接
运行结果