1

When I read first 4 bytes with python code

len = fobj.read(4)

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.

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.

Thank you for any suggestion!

Community
  • 1
  • 1
dehiker
  • 454
  • 1
  • 8
  • 21

2 Answers2

7
>>> import struct
>>> struct.unpack('<i', 'o\xf2\x00\x00')
(62063,)
jamylak
  • 128,818
  • 30
  • 231
  • 230
1

I Tried this and got the answer:

>>> print(int.from_bytes(b'o\xf2\x00\x00','little'))
62063
JenilDave
  • 606
  • 6
  • 14