With the data type "union", I can convert a float to an int. Like this:
#include <stdio.h>
#include <stdlib.h>
int float_as_int(float f)
{
union { int i; float f; } u;
u.f = f;
return u.i;
}
int main() {
float f = 1.01;
printf("float = %f\n", f);
printf("int = %d\n", float_as_int(f));
system("pause");
}
The result of this code is:
float = 1.010000
int = 1065437102
However, from this value "1065437102" how can I get the information about the float it represents. For example: The 32-bit number which it stores and position the "point" (fixed point on the base 2)?
EDIT: The answer to that question was asked here -> How to get the sign, mantissa and exponent of a floating point number