There is no conversion from
float
to
binary since
float
variables are already stored in the binary form stated by the
IEEE_754 standard[
^].
If you need to show how a float is stored in a human friendly format, then you may use, for instance, the following code:
#include <stdio.h>
void out_float(float f)
{
size_t size = sizeof(f);
unsigned char * p = (unsigned char *) &f;
p += size-1;
while (size--)
{
int n;
for (n=0; n<8; n++)
{
putchar('0' + (*p & 128 ? 1 : 0));
*p <<= 1;
}
p--;
}
}
int main()
{
float f = -118.625f;
out_float(f);
putchar('\n');
return 0;
}