-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"

2
  • 1
    What have you tried already and where are you stuck? Commented Sep 30, 2018 at 18:33
  • 2
    You can find the answer here: link Commented Sep 30, 2018 at 18:37

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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')) 

2 Comments

What is bytes here? What do you do with string?
well, the bytes here are the hex numbers. Hexadecimal numbers are defined as 0-9 and A-F. My apologies don't need string I thought I would. Thanks for keeping me on my toes with the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.