I am given strings structured as such: "\x0C\x00Maximilianus\xf4\x01" and I would like to dynamically extract first two and last two bytes and convert them to decimals. The encoding for this should be UTF-8 little-endian unsigned.
"\x0C\x00" equals 12
"\xf4\x01" equals 500
I am not able to find any function that would be able to do that. Also replacing "\x" in the string doesn't work as I cannot manipulate with escape characters.
Any thoughts?
struct.pack()to create it then usestruct.unpack()to convert it back.Maximilianushas 12 chars so"\x0C\x00"can be information how long is string and it can be some system to send data in networkprint(struct.unpack('hh', b"\x0C\x00\xf4\x01"))gives(12, 500)