下面是python的表达式。它将整数转换为二进制。在
>>>octtab = {'0':'000', '1':'001', '2':'010', '3':'011',
'4':'100', '5':'101', '6':'110', '7':'111'}
>>>def bin1(d, width=0):
"integer to binary (string)"
s = "%o" % d
b = ''
for el in s:
b += octtab[el]
if width > 0:
if len(s) > width:
return b[:width]
b = b.zfill(width)
return b
我不知道%o的意思。提前谢谢:)
%o
是string formatting。您使用%o
表示八进制数(即以8为基数的数字):相关问题 更多 >
编程相关推荐