Handling with floats can  be irritating while it is one of the non-integral datatypes. This means that the displayed value (e.g. via printf(“%f”,somefloat); )  is different to the one actualy stored in memory. This is caused by IEEE 754

To get the real values we have to go inside the float. A cast wouldn’t do the job, because it would just turn a 3.1415 into 3[1]
C has a very nice keyword which can help us: union
Instead of casting datatypes, we just map different variables with different datatypes to the exact same memory.

The following 4-liner will do the trick for us.

union floatDbg{
    float f;
    unsigned char c[4];

Now we can access every byte of the float and get the real value. To know what the values are telling us, we would need to know the IEEE754 Algorithm. But that is another story.

union floatDbg dbg;
dbg.f = 13.37;

// Decimal output
printf("%.2f -> %d %d %d %d\n", 
       dbg.c[0],dbg.c[1],dbg.c[2],dbg.c[3]); // 13.37 -> 133 235 85 65

// Hex output
printf("%.2f -> %x %x %x %x\n", 
       dbg.c[0],dbg.c[1],dbg.c[2],dbg.c[3]); // 13.37 -> 85 eb 55 41

[1] This turns only out to be true if you are living in the US-State Indiana

Hits: 375