猫史档案馆


【Python作品分享】二进制【教程贴】

用户:_幻灵__幻灵_查看:0 回复:0 评论:0 创建时间:2022-02-15T12:11:48


【作品展示】

center_image

 

【作品介绍】

二进制代码

 

【作品源代码】

def Dec2Bin(dec):
    temp = []
    result = ''
    while dec:
        quo = dec % 2
        dec = dec // 2
        temp.append(quo)
    while temp:
        result += str(temp.pop())

    return result


print(Dec2Bin(62))



def bilibili(b):
    t = []
    i = ''
    e = ''
    while b < 0:
        b = -b
        i = '-'
    while b//2 != 0:
        a = b % 2
        t.append(a)
        b = b//2
    if b != 0:
        t.append(1)
    else:
        t.append(0)
    while t:
        e += str(t.pop())

    return (i+"0b"+e)


#b要为整数,效果同Python3.8内置函数bin()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页