I have a hex string like:
data = \"437c2123\"
I want to convert this string to a sequence of characters according to the ASCII table. The
In [17]: data = "437c2123"
In [18]: ''.join(chr(int(data[i:i+2], 16)) for i in range(0, len(data), 2))
Out[18]: 'C|!#'
Here:
for i in range(0, len(data), 2)
iterates over every second position in data
: 0
, 2
, 4
etc.data[i:i+2]
looks at every pair of hex digits '43'
, '7c'
, etc.chr(int(..., 16))
converts the pair of hex digits into the corresponding character.''.join(...)
merges the characters into a single string.