Mat*_*ner 8 python int byte endianness python-3.x
我正在寻找一个采用任意长度 bytes对象的函数,并将其转换为int.显然,字节顺序是此函数的必需参数.
我敢肯定,我遇到了无论是内置bytes或int,但无法找到它了.关于使用struct和手动枚举各个字节值的类似问题,有很多答案.有没有使用类似C的假设/模块进行转换的内置函数?
def int(bytes, 'little') -> int
Run Code Online (Sandbox Code Playgroud)
Kab*_*bie 17
从3.2开始:
>>> int.from_bytes(b'\xFF\x00','little')
255
>>> int.from_bytes(b'\xFF\x00','big')
65280
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6687 次 |
| 最近记录: |