这是我想要的功能:-
http://docs.python.org/3/library/stdtypes.html#int.to_bytes 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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)