我有一段代码可以执行整数到原始字符串转换,但它不需要很长时间。任何解决方案?
def intToBytes(integer):
hex_form = hex(integer)[2:]; # 2: gets rid of leading 0x
if (len(hex_form) % 2):
hex_form = '0' + hex_form;
return bytearray.fromhex(hex_form)
答案 0 :(得分:2)
您可以在出现时删除结尾'L'
:
def intToBytes(integer):
hex_form = hex(integer)[2:]; # 2: gets rid of leading 0x
if hex_form[-1:] == 'L':
# Remove final `L` from arbitrary precision integers
hex_form = hex_form[:-1]
if (len(hex_form) % 2):
hex_form = '0' + hex_form;
return bytearray.fromhex(hex_form)