我有一个我继承的 python 程序,正在尝试扩展。
我已经将一个两字节长的字符串提取到一个名为 pS 的字符串中。
pS 第一个字节是0x01,第二个字节是0x20,十进制值== 288
我一直在尝试获取它的整数值,我使用了以下形式的行
x = int(pS[0:2], 16) # this was fat fingered a while back and read [0:3]
获取消息
ValueError: invalid literal for int() with base 16: '\x01 '
另一位 C 程序员和我一直在谷歌搜索并试图让它工作一整天。
请提出建议。
最佳答案
关于python - 如何将 2 个字节长的字符串转换为 python 中的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/826284/