是否有任何python模块可以帮助我将字符串转换为64位整数?
(此字符串的最大长度为8个字符,因此应该很长)。

我想避免不得不编写自己的方法。

例子:

Input String   Hex          result (Base-10 Integer)
'Y'            59           89
'YZ'           59 5a        22874
...

最佳答案

这是 struct 的工作:

>>> s = 'YZ'
>>> struct.unpack('>Q', '\x00' * (8 - len(s)) + s)
(22874,)

或更棘手的是:
>>> int(s.encode('hex'), 16)
22874

关于python - 如何将字符串转换为以10为基数的表示形式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10716796/

10-12 16:39
查看更多