十进制转换成二进制
十进制转二进制通过不断的查找资料最终才有一点思路
- 代码如下(指数无法确定)
`y = eval(input('the number : '))
if y>0:
sign = 0
else:
sign = 1
x = abs(y)
a = int(x)
e = bin(a).replace('0b','')
f = e[0].strip('0') + e[1:]
b = x-a
c = bin(len(bin(a))+126).replace('0b','')
i = b
a = 1
even = []
while a <9 :
i *= 2
even.append(int(i))
i = i - int(i)
a += 1
list = [str(n) for n in even ]
list2 = ''.join(list)
print(str(sign)+str(c)+str(f)+list2)
`
- 请各位帮忙纠错,谢谢。