So let's say I have this line of text 0x730x700x770x770x7a. As some of you might have noticed, those are multiple hex numbers bunched together. What I want is a way to remove the 0x prefix despite the position it is on the line of text. Take in mind that the above line of multiple hex values is just an example. My goal after removing the prefix is to put every different hex value inside a list and turn them into ASCII. Any advice would be appreciated because I don't have much knowledge with Python.
2 Answers
Don't remove the prefixes. Use built-in Python facilities to get your list of integers directly.
>>> a = "0x730x700x770x770x7a"
>>> list(int(a[i:i+4],16) for i in range(0,len(a),4))
[115, 112, 119, 119, 122]
Try the following:
num = "0x730x700x770x770x7a"
lst = num.split("0x")[1:]
asciilst = []
for x in lst:
print(x)
bytes_object = bytes.fromhex(x)
ascii_string = bytes_object.decode("ASCII")
asciilst.append(ascii_string)
print(asciilst)
0x
. w3schools.com/python/ref_string_split.asppython
tag, but you have added no code to your question.0x
numbers to begin with? That's a terrible way to store data.0x05
or are they written as0x5
?