I have a function which encode float number to binary. I split float number by "." and convert both parts to binary. After i concatenate results. Left part I encode by simple convert bin(left_part). Right part I encode by next algorithm:
while count:
val *= 2
if val >= 1:
val_bin += "1"
else:
val_bin += "0"
val %= 1
count -= 1
return val_bin
I have found this solution on the internet. But I can't found out how to convert back right part to float number in decimal. How i can do it?
I only see the way of full exhaustive search: Example: I have "00110011". We move from right to left. In first step we have "1". That means in the step value may be in interval "1.000 to 1.999". In the next step we have another "1". That means that value in the first step was in interval "1.500 to 1.999". In current step we have the next interval "1.001 to 1.999". Next step we have "0". That means in previous step value was in interval 1.000 to 1.499". etc. And after all iterations we will not have a accurate result. Result always will be in the interval. I may be wrong.