标签:eee work tno 字符 == pac color oca code
求解方法:
1、整数求余
2、重复进行,整数除2再求余,直到除数为0
3、拼接余数
4、反转字符串
def int2two(intNo): twoStr=‘‘ if intNo == 0: twoStr = ‘0‘ while intNo != 0: intMod = intNo % 2 intNo = intNo//2 twoStr = twoStr + str(intMod) return ‘0b%08d‘ %int(twoStr[::-1]) if __name__ == ‘__main__‘: print(int2two(2796202)) print(bin(2796202))
运行结果:
C:\Users\suneee\AppData\Local\Programs\Python\Python36\python.exe E:/wangjz/PyWorkSpace/LearnPython/int2bin.py
0b1010101010101010101010
0b1010101010101010101010
Process finished with exit code 0
标签:eee work tno 字符 == pac color oca code
原文地址:https://www.cnblogs.com/kusy/p/9401524.html