How to convert hex string 'o\xf2\x00\x00' into a int32?

后端 未结 2 1919
面向向阳花
面向向阳花 2021-01-24 00:27

When I read first 4 bytes with python code

len = fobj.read(4)

I got \'o\\xf2\\x00\\x00\'. This should be an int32, an

相关标签:
2条回答
  • 2021-01-24 00:42

    I Tried this and got the answer:

    >>> print(int.from_bytes(b'o\xf2\x00\x00','little'))
    62063
    
    0 讨论(0)
  • 2021-01-24 00:52
    >>> import struct
    >>> struct.unpack('<i', 'o\xf2\x00\x00')
    (62063,)
    
    0 讨论(0)
提交回复
热议问题