0

I have the following code which in Python 2.7 works exactly how I want. It takes a series of integer values in regs and converts each value to its character equivalent. For example, 21365 ==> 0x5375 amd would result in "Su".

RegString = ""
    for i in range(length):
        if regs[start+i]!=0:
            print (" Regs is ", regs[start+1], " Hex  is ", hex(regs[start+i]), " Striped is ", str(format(regs[start+i],'x') ))
            RegString = RegString + str(format(regs[start+i],'x').decode('hex'))

However in Python 3, the decode('hex') throws an error. Now, I looked at many posting with this problem, but have not been able to apply those solutons to my problem, that is to modify the above code to work in Python 3.

Here is the output when I try to run this section of code:

Regs is 20341 Hex is 0x4f75 Striped is 4f75

Traceback (most recent call last): File "v3Test.py", line 23, in Get_Regester_String RegString = RegString + str(format(regs[start+i],'x').decode('hex'))

AttributeError: 'str' object has no attribute 'decode'

Can anyone point me in the right direction to fix the above failing statement so that it will work in Python 3.7 "RegString = RegString + str(format(regs[start+i],'x').decode('hex')) ". Thanks...RDK

0

1 Answer 1

1

For python 3 use the following process

bytes.fromhex(format(regs[start+i],'x')).decode('utf-8')
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks. I worked on this for several hours before I posted the question. Your answer works like a champ and a lot simpler that some of the things I tried. Bravo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.