如何将十六进制字符串'o\xf2\x00\x00'转换为int32? [英] How to convert hex string 'o\xf2\x00\x00' into a int32?

查看:539
本文介绍了如何将十六进制字符串'o\xf2\x00\x00'转换为int32?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用python代码读取前4个字节的时候

When I read first 4 bytes with python code

len = fobj.read(4)

我得到了'o\xf2\x00\x00' 。这应该是一个 int32 ,当我用其他工具(例如 matlab )读取文件时,它会给出 62063

I got 'o\xf2\x00\x00'. This should be an int32, and when I read the file with other tool (matlab, for example), it gives 62063.

任何人都可以提供关于如何将 code>字符串转换为python中的 int

Could anybody give any hints on how I can convert the hex string into an int in python?

我读过

I've read this hex string to int conversion discussion, but found no help.

感谢您的任何建议!

推荐答案

>>> import struct
>>> struct.unpack('<i', 'o\xf2\x00\x00')
(62063,)

这篇关于如何将十六进制字符串'o\xf2\x00\x00'转换为int32?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆