Python二进制小数转化 如下图

img

>>> while True:
    content = input('请输入浮点数(退出请输入end):')
    if content == 'end':
        break
    integer, decimal = content.split('.')
    result = int(integer, base=2) + int(decimal, base=2)/pow(2, len(decimal))
    print('%.5f'%result)

    
请输入浮点数(退出请输入end):101.0011
5.18750
请输入浮点数(退出请输入end):01101.101011
13.67188
请输入浮点数(退出请输入end):1100.01
12.25000
请输入浮点数(退出请输入end):end