int main()
{
int integral, binaryInt = 0, i = 1;
float binaryFract = 0, k =0.1f, fractional, temp1, binaryTotal, f;
printf("***** Convert float to binary *******\n");
printf("\nEnter float value : ");
scanf("%f",&f);
//Separating the integral value from the floating point variable
integral = (int)f;
//Separating the fractional value from the variable
fractional = f - (int)f;
//Loop for converting decimal to binary
while(integral>0)
{
binaryInt = binaryInt + integral % 2 * i;
i = i * 10;
integral = integral / 2;
}
printf("%d",binaryInt);
return 0;
}
in the above code , why does "while loop" give an output of 00 instead of 0 when adding 0+0?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
It doesn't.
but in the above code if we get 0 as product of intregal%2*100 and it gets added to 11 then the answer should be 11 but here we are getting something like 011.
I cannot replicate your problem, please provide input data.