########## Begin ##########
def BinToDec(b):
s = 0
L = str(b).split('.')
if len(L) == 2:
# 有小数
l = [int(i) for i in L[0]]
lx = [int(i) for i in L[1]]
l,lx = l[::-1],lx[::-1]
for i in range(len(l)-1,-1-len(lx),-1):
if i<0:
s = s+lx[i]*2**i
else:
s = s+l[i]*2**i
else:
l = [int(i) for i in L[0]]
l = l[::-1]
for i in range(len(l)-1,-1,-1):
s = s + l[i]*2**i
return s
########## End ##########
b = input()
d = BinToDec(b)
print('%s -> %s' % (b, d))
二进制到十进制-输入为正数
最新推荐文章于 2021-11-23 17:16:02 发布