In [1]:
def fracbin(x, m=10):
    r = x
    b = []
    for k in range(1, m):
        if r >= 2**(-k):
            b.append(1)
            r = r - 2**(-k)
        else:
            b.append(0)
    return ''.join(map(str,b))
In [2]:
fracbin(0.8125, 8)
Out[2]:
'1101000'
In [3]:
fracbin(0.1,25)
Out[3]:
'000110011001100110011001'
In [4]:
fracbin(0.1,100)
Out[4]:
'000110011001100110011001100110011001100110011001100110100000000000000000000000000000000000000000000'

What happened here?!