-3

I've been trying to convert this string:

str = "68656c6c6f20776f726421"

to recover a ASCII value:

str = "hello word!"

I need some help with this please.

EDIT

Sorry for not giving more information, I'm a newbie, unfortunately.

but reading several pages of this wonderful site I found the solution.

the problem was that I got the string of a file, and a \n was printed, changing the length of the string.

Solution here: Python: binascii.a2b_hex gives "Odd-length string"

  • 1
    What have you tried already and where are you stuck? – NPE Sep 30 '18 at 18:33
  • 2
    You can find the answer here: [link](https://stackoverflow.com/questions/9641440/convert-from-ascii-string-encoded-in-hex-to-plain-ascii) – Henry Yik Sep 30 '18 at 18:37

2 Answers2

0

have you tried

codecs.decode(str, "hex").decode('utf-8')

You may need to assign this to a variable or print the results to see the output depending on your use case.

Philip Bal
  • 23
  • 9
0

If I was doing this solution it would be the following:

data = bytes.fromhex(b'68656c6c6f20776f726421'.decode("ascii"))
print('The hex value converted to ascii is the following:',data.decode('utf-8'))