#!/usr/bin/python
# coding:utf-8

'''
@author:fojo
Email:puzzle@92linux.cn
'''

def TransBinary(number):

    tmp = []
    while number // 2 != number :
        quyu = number % 2
        number = number // 2
        tmp.append(quyu)

    tmp = tmp[::-1] # 倒序排列

    # 将列表转换成字符串
    Result = [ str(i) for i in tmp ]
    Result = ''.join(Result)

    return Result

number = 2
ls1 = TransBinary(number)
print(number,'的二进制为:',ls1)
Last modification:September 17th, 2019 at 05:25 pm
If you think my article is useful to you, please feel free to appreciate