python - 字节串到长值

标签 python string python-2.7 arrays

字节串转长值:

我有一串十六进制值,如“,ff,fe,d0,ea”,如何将它们转换为(大端)长值?代码片段:

dataStr = ',ff,fe,d0,ea'
dataVal = struct.unpack('>l', '\xff\xfe\xd0\xea')[0]
print dataStr, ' = ', dataVal      # prints out ,ff,fe,d0,ea  =  -77590

我认为 \ 是一个不可打印的字符,所以我相信我的问题真的是(给定片段),我如何从 ,ff,fe,d0,ea\xff\xfe\xd0\xea?或任何适合 struct.unpack 函数的数组值?

最佳答案

以下将解码 ',ff,fe,d0,ea''\xff\xfe\xd0\xea'

dataStr = ',ff,fe,d0,ea'.replace(',', r'\x').decode('string-escape')

关于python - 字节串到长值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27607665/

相关文章:

相当于列表中另一个的python项目

python - 如何跳过或忽略 python 装饰器

Java 十六进制字符串连接校验和

c++ - 在库类(std::string)上使用 memset 时出现 "undefined behaviors"的原因是什么?

python - tfidf.transform() 函数没有返回正确的值

python - 在python中过滤以进行 Elasticsearch

python - 查询 Django 模型时,有没有办法匹配字段中的每个字符串

python - 根据列表创建多个目录

python - for/if循环和python中变量的范围

Javascript 字符串是原始类型?