Convert floating number to binary representation program in C
<pre><code>#include "ieee754.h"
#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

//This program convert a floating number to its binary representation (IEEE754) in computer memory
int main() {
    long double f, binaryTotal, binaryFrac = 0.0, frac, fracFractor = 0.1;
    long int integer, binaryInt = 0;
    long int p = 0, rem, temp;

    printf("\nEnter floating number: ");
    scanf("%Lf", &amp;f);

    //separate the integer part from the input floating number
    integer = (int)f;

    //separate the fractional part from the input floating number
    frac = f - integer;

    //loop to convert integer part to binary
    while (integer != 0) {
        rem = integer % 2;
        binaryInt = binaryInt + rem *pow(10, p);
        integer = integer / 2;
        p++;
    }

    //loop to convert fractional part to binary
    while (frac != 0) {
        frac = frac * 2;
        temp = frac;
        binaryFrac = binaryFrac + fracFractor * temp;
        if (temp == 1)
            frac = frac - temp;

        fracFractor = fracFractor / 10;
    }

    binaryTotal = binaryInt + binaryFrac;
    printf("binary equivalent = %Lf\n", binaryTotal);
}
</code></pre>

<p>I'm trying to convert floating number to binary representation (64-bit). This code is working but not perfect. For example, when I convert <code>.575</code> it gives me <code>0.100100</code> but when I do the conversion using this website <a href="http://www.exploringbinary.com/floating-point-converter/" rel="nofollow noreferrer">http://www.exploringbinary.com/floating-point-converter/</a>, the right output should be <code>0.1001001100110011001100110011001100110011001100110011</code></p>

<p>I am having trouble understanding what makes my code truncate the number. Could anyone help me how to fix it? I appreciate your help. </p>