I have a hexadecimal string which I have received from internet (SSL client). It is as follows: "\x7f\xab\xff". This string is actually the length of something. I need to calculate the integer value of a sub-string in the above string (based on starting and ending position). How do I do that.
I tried struct.pack and unpack. It did not work I tried doing a split based on \x, and that gave some UTF error I tried converting the string to a raw string. Even that did not work
r"\xff\x7f".replace('\x' , '')
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in
position 0-1: truncated \xXX escape
>>> "\xff\x7f"[1]
'\x7f'
>>> "\xff\x7f"[0]
'ÿ'
>>> "\xff\x7f"[1]
'\x7f'
>>> "\xff\x7f"[0]
'ÿ'