#coding=utf-8 def getbin(a): out = "" # 辗转相除法 while (1): div = a // 2 mod = a % 2 out += str(mod) if (div == 0): break a = div return out[::-1] print(getbin(11))
输出
1011
参考:
https://www.nuoweb.com/scripts/3158.html
https://jingyan.baidu.com/article/f0e83a255ca20422e59101f5.html