in reply to Converting decimals to binary

Would it not work to simply multiply the value in question by the number of unique integers you wish to approximate, and take the integer portion of the result?

print int(.99 * 4); # output = 3 print int(.2 * 4); # output = 0

From there you simply need to convert the resulting number into a binary value. For that, use pack.

May the Force be with you