I want to convert an integer value to a string of hex values, in little endian. For example, 5707435436569584000 would become '\x4a\xe2\x34\x4f\x4a\xe2\x34\x4f'.
All my googlefu is finding for me is hex(..) which gives me '0x4f34e24a4f34e180' which is not what I want.
I could probably manually split up that string and build the one I want but I’m hoping somone can point me to a better option.
You need to use the
structmodule:Here
<indicates little-endian, andQthat we want to pack a unsigned long long (8 bytes).Note that Python will use ASCII characters for any byte that falls within the printable ASCII range to represent the resulting bytestring, hence the
14OJ,24OandJparts of the above result: