Python int to binary string?

后端 未结 30 1630
执念已碎
执念已碎 2020-11-22 05:34

Are there any canned Python methods to convert an Integer (or Long) into a binary string in Python?

There are a myriad of dec2bin() functions out on Google... But I

30条回答
  •  盖世英雄少女心
    2020-11-22 05:51

    try:
        while True:
            p = ""
            a = input()
            while a != 0:
                l = a % 2
                b = a - l
                a = b / 2
                p = str(l) + p
            print(p)
    except:
        print ("write 1 number")
    

提交回复
热议问题