// frac_bin.c convert fraction to binary fraction #include int main() { double x; long int i; printf("frac_bin.c running\n"); x = 0.375; // 3 * 0.1 + 7 * 0.01 + 5 * 0.001 printf("x=%f\n", x); printf("."); x = x*2.0; i = x; // want integer part, no rounding, could compare to 1.0 printf("%1ld", i); if(i!=0) { x = x - 1.0; } // i==0 comes here, nothing to do x = x*2.0; i = x; // want integer part, no rounding, could compare to 1.0 printf("%1ld", i); if(i!=0) { x = x - 1.0; } // i==0 comes here, nothing to do x = x*2.0; i = x; // want integer part, no rounding, could compare to 1.0 printf("%1ld", i); if(i!=0) { x = x - 1.0; } // i==0 comes here, nothing to do printf("\n"); return 0; } // end frac_bin.c