gpt4 book ai didi

python - Python 3 to_bytes 是否已向后移植到 python 2.7?

转载 作者:太空狗 更新时间:2023-10-29 21:12:36 25 4
gpt4 key购买 nike

这是我追求的功能:-

http://docs.python.org/3/library/stdtypes.html#int.to_bytes

我需要大端支持。

最佳答案

根据@nneonneo 的回答,这里有一个模拟 to_bytes API 的函数:

def to_bytes(n, length, endianess='big'):
h = '%x' % n
s = ('0'*(len(h) % 2) + h).zfill(length*2).decode('hex')
return s if endianess == 'big' else s[::-1]

关于python - Python 3 to_bytes 是否已向后移植到 python 2.7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16022556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com