Binary/hexadecimal to floating point Programming (similar to mutual conversion), hexadecimal points
Conversion Program:
// Input a decimal integer. The output float indicating the same memory layout is inline float i2f (int I) {float f = 0; assert (sizeof (int) = sizeof (float); memcpy (& f, & I, 4); return f;} inline double ll2d (long ll) {double d = 0; assert (sizeof (double) = sizeof (long); memcpy (& d, & ll, 8); return d ;}/ * Ask hovertree.com */
Application:
Int I =-1052770304; // This is the result of the disassembly. It is actually a float type, =-12.0 float f = i2f (I ); printf ("f = % f \ n", f); long ll = 0x4004000000000000L; // This is shown in the memory. The actual type is double 2.5 double d = ll2d (ll); printf ("d = % f \ n", d);/* why do you ask hovertree.com */
The principle is to copy memory data and then explain it with different data types.
Recommended: http://www.cnblogs.com/roucheng/p/cpp11.html