title: Correct algorithm to convert binary floating point "1101.11" into decimal (13.75)?
body: <p>I have written a program in C to convert a floating point number <a href="http://kipirvine.com/asm/workbook/floating_tut.htm" rel="nofollow">represented in binary</a> (<code>1101.11</code>) into a decimal (<code>13.75</code>). </p>
  
  <p>However, I cannot seem to get the correct value out of the algorithm.</p>
  
  <p>What is the correct method for converting a binary floating point number into a decimal?</p>
  
  <p>I am using Dev CPP compiler (32 bit). The algorithm is defined below:</p>
  
  <pre><code>void b2d(double p, double q )
  {
     double rem, dec=0, main, f, i, t=0;
  
     /* integer part operation */    
     while ( p &gt;= 1 )
     {
       rem = (int)fmod(p, 10);
       p = (int)(p / 10);
       dec = dec + rem * pow(2, t);
       t++;
     }
  
     /* fractional part operation */
     t = 1; //assigning '1' to use 't' in new operation
     while( q &gt; 0 )
     {
       main = q * 10;
       q = modf(main, &amp;i); //extration of frational part(q) and integer part(i)
       dec = dec+i*pow(2, -t);
       t++;
     }
  
     printf("\nthe decimal value=%lf\n",dec); //prints the final output
  }
  
  int main()
  {
     double bin, a, f;
  
     printf("Enter binary number to convert:\n");
     scanf("%lf",&amp;bin);
  
     /* separation of integer part and decimal part */
     a = (int)bin;
     f = bin - a;       
     b2d(a, f); // function calling for conversion
  
     getch();
     return 0;
  }
  </code></pre>