float and int types are all 4 bytes, and I'm trying to convert this way:
unsigned int x = 0;
x = ~x>>1;
float f = *((float *)&x);
printf("%f\n", f);
Since the first bit in the floating-point c-number represents +/-, and the next 8 bits expin 2^(exp-127), and the rest will be converted to 0.xxxxx..., this means that I can get the maximum floating-point number: 0|11111111|111...111but finally, I get nan.
So is something wrong?
source
share