我有下一个值。
value = bytearray(b'\x85\x13\xbd|\xfb\xbc\xc3\x95\xbeL6L\xfa\xbf0U_`$]\xca\xee]z\xef\xa0\xd6(\x15\x8b\xca\x0e\x1f7\xa9\xf0\xa4\x98\xc5\xdf\xcdM5\xef\xc2\x052`\xeb\x13\xd9\x99B.\x95\xb2\xbd\x96\xd9\x14\xe6F\x9e\xfd\xd8\x00')
当我尝试在Python3.x中进行转换时,它能够很好地工作。
>>> int.from_bytes(value, byteorder='little')
2909369579440607969688280064437289348250138784421305732473112318543540722321676649649580720015118044118243611774710427666475769804427735898727217762490192773
如何在Python2.7中进行转换?我已经阅读了将字节字符串转换为整数(Python)
的内容。struct.unpack(fmt, value)[0]
但是不知道如何使用fmt。
struct.unpack
对于你的情况不合适,因为你有太多字节。你需要查看 https://dev59.com/J3RB5IYBdhLWcg3w-8Lo#444814。 - Robᵩint(str(value[::-1]).encode('hex'), 16)
或者sum(v << (8 * i) for i,v in enumerate(value))
。 - PM 2Ring