/** * @brief The entry of this program * * @param argc counts of argument * @param argv argument variables stored in * * @return EXIT_SUCCESS */ intmain(int argc, char **argv) { float f = 7.5; unsignedint i = *(unsignedint *)&f; printf ("i:0x%x\n", i); return EXIT_SUCCESS; } //end of function main
输出结果
i:0x40F00000
解释
浮点数格式
| |
|<------------------------4Bytes/32Bits------------------------>|
| |
|1Bit(Sign:+/-) 23Bits(Digit) |
+-+---------------+---------------------------------------------+
|x|x x x x x x x x|x x x x x x x x x x x x x x x x x x x x x x x|
+-+---------------++-+-+----------------------------------------+
8Bits(Exp) | | +-(2^-3)
| +-(2^-2)
+-(2^-1)