加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 10:41:08 所属栏目:Python 来源:网络整理
导读:Python3编码转换大全 进制转换 其他进制转十进制 2 - 10 ```python ? 1 int( ‘ 1100 ‘ ,2 ) 2 12 ? ``` 8 - 10 ```python int(‘1100‘,8) 576 ``` 16 - 10 ```python int(‘1100’,16) 4352 ``` 十进制转其他进制 10 - 2 ```python bin(170) ‘0b10101010

Python3编码转换大全

进制转换

其他进制转十进制

2 -> 10

```python
?1 int(1100,2) 2 12?
```

8 -> 10

```python
int(‘1100‘,8)
576
```

16 -> 10

```python
int(‘1100’,16)
4352
```

十进制转其他进制

10 -> 2

```python
bin(170)
‘0b10101010‘
```

10 - > 8

```python
oct(170)
‘0o252’
```

10 -> 16

```python
hex(170)
‘0xaa’
```

Html编码

```python
import html
html.unescape(‘&#102‘)
’f‘
```

当然也可以多个字符

```python
import html
html.unescape(‘flag‘)
‘flag‘
```

Base编码

加密

base64

```python
import base64
a=b‘233‘
b=base64.b64encode(a)
b
b‘MjMz‘
```

base32

```python
import base64
a=b‘233‘
b=base64.b32encode(a)
b
b‘GIZTG===‘
```

base16

```python
import base64
a=b‘233‘
b=base64.b16encode(a)
b
b‘323333‘
```

解码

base64

```python
import base64
a=b‘MjMz‘
b=base64.b64encode(a)
b
b‘233‘
```

base32

```python
import base64
a=b‘GIZTG===‘
b=base64.b32decode(a)
b
b‘233‘
```

base16

```python
import base64
a=b‘323333‘
b=base64.b16decode(a)
b
b‘233‘
```

至于base58

这个因为比较晚,所以在另外一个库base58里

编码

```python
import base58
a=b‘233‘
b=base58.b58encode(a)
b
b‘HryY‘
```

解码

```pythonimport base58a=b‘HryY‘b=base58.b58encode(a)bb‘233‘```

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读