Reputation: 349
I need to use struct module to pack hex string of '4EA7
' to 2bytes, here is what I did:
struct.pack('<H',int('4EA7',16))
'\xa7N'
question is why it's not returning \x4E\xA7
?
Thanks
Upvotes: 1
Views: 1741
Reputation: 3357
The thing you're looking for would be:
In [1]: struct.pack('>H',int('4EA7',16))
Out[1]: b'N\xa7'
\x4E
in https://ascii.cl/ is the letter 'N'
an A7
is printed as is.
Upvotes: 2