Jose Ortiz Jose Ortiz - 4 months ago 30
C Question

how to tell the value of a float pointer when it has been referenced from an integer? ex: float *f= (float *)someInteger

I cannot figure out to convert the value of a referenced

pointer when it is referenced from an integer casted into a
pointer. I'm sorry if I'm wording this incorrectly. Here is an example of what I mean:

#include <stdio.h>

main() {
int i;
float *f;

i = 1092616192;

f = (float *)&i;

printf("i is %d and f is %f\n", i, *f);

the output for
. How did I get that result?


Normally, the value of 1092616192 in hexadecimal is 0x41200000.

In floating-point, that will give you:

sign = positive (0b)
exponent = 130, 2^3 (10000010b)
significand = 2097152, 1.25 (01000000000000000000000b)

2^3*1.25 = 8 *1.25 = 10

To explain the exponent part uses an offset encoding, so you have to subtract 127 from it to get the real value. 130 - 127 = 3. And since this is a binary encoding, we use 2 as the base. 2 ^ 3 = 8.

To explain the significand part, you start with an invisible 'whole' value of 1. the uppermost (leftmost) bit is half of that, 0.5. The next bit is half of 0.5, 0.25. Because only the 0.25 bit and the default '1' bit is set, the significand represents 1 + 0.25 = 1.25.