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编码

加密
base64
import base64
a=b'233'
b=base64.b64encode(a)
b
b'MjMz'
base32
import base64
a=b'233'
b=base64.b32encode(a)
b
b'GIZTG==='
base16
import base64
a=b'233'
b=base64.b16encode(a)
b
b'323333'
解码
base64
import base64
a=b'MjMz'
b=base64.b64encode(a)
b
b'233'
base32
import base64
a=b'GIZTG==='
b=base64.b32decode(a)
b
b'233'
base16
import base64
a=b'323333'
b=base64.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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值