您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页Python3中的编码转换大全(不定期更新)

Python3中的编码转换大全(不定期更新)

来源:华佗小知识

Python3编码转换大全

进制转换

其他进制转十进制
2 -> 10
int('1100',2)
12
8 -> 10
int('1100',8)
576
16 -> 10
int('1100',16)
4352
十进制转其他进制
10 -> 2
bin(170)
'0b10101010'
10 - > 8
oct(170)
'0o252'
10 -> 16
hex(170)
'0xaa'

Html编码

import html
html.unescape('&#102')
'f'

当然也可以多个字符

import html
html.unescape('flag')
'flag'

Base编码

加密
base
import base
a=b'233'
b=base.bencode(a)
b
b'MjMz'
base32
import base
a=b'233'
b=base.b32encode(a)
b
b'GIZTG==='
base16
import base
a=b'233'
b=base.b16encode(a)
b
b'323333'
解码
base
import base
a=b'MjMz'
b=base.bencode(a)
b
b'233'
base32
import base
a=b'GIZTG==='
b=base.b32decode(a)
b
b'233'
base16
import base
a=b'323333'
b=base.b16decode(a)
b
b'233'

至于base58

这个因为比较晚,所以在另外一个库base58里
编码
import base58
a=b'233'
b=base58.b58encode(a)
b
b'HryY'
解码
import base58
a=b'HryY'
b=base58.b58encode(a)
b
b'233'

转载于:https://www.cnblogs.com/dawn-whisper/p/11545521.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务