IEEE 754:
https://zh.wikipedia.org/wiki/IEEE_754
FLOAT:
31 30 22 15 7 0
+---+----------+---------+----------+----------+
| | | |
+---+----------+---------+----------+----------+
+ S + E + M +
EXAMPLE(5.5):
=============================
int main() {
float a = 5.5;
int *p = &a;
printf("%d\n", *p);
printf("%X\n", *p);
}
gcc -o main main.c; ./main
十进制: 1085276160
十六进制: 40B00000
=============================
十进制 = 二进制 = 二进制指数形式
5.5 = 101.1 = 1.011 * 2^2
==> S=0 E=2 M = 11
31 30 22 15 7 0
+---+----------+---------+----------+----------+
| 0 | 10000001 | 0110000 | 00000000 | 00000000 |
+---+----------+---------+----------+----------+
+ S + E + M +
转换成INT:
二进制: 01000000101100000000000000000000
十进制: 1085276160
十六进制: 40B00000
EXAMPLE(5.1):
===========================================
int main() {
float a = 5.1;
int *p = &a;
printf("Float:\t%f\n", a);
printf("十进制:\t%d\n", *p);
printf("十六进制:\t%X\n", *p);
}
gcc -o main main.c; ./main
Float: 5.100000
十进制: 1084437299
十六进制: 40A33333
===========================================
存储形式:0b01000000101000110011001100110011
有效尾数:01000110011001100110011
表达方式:1.01000110011001100110011 * 2^2 ==> 101.000110011001100110011
101 ==> 5
0.000110011001100110011 ==> 2^-4 + 2^-5 + 2^-8 + 2^-9 + 2^-12 + 2^-13 + 2^-16 + 2^-17 + 2^-20 + 2^-21
实际表达: 5.09999990463256836
保留6位小数: 5.100000