The working solution which returns the correct result and works for any string :)
Python 3.x
def convert(chars): if isinstance(chars, bytes): chars = chars.decode('ascii') chars = [''.join(c) for c in zip(chars[::4], chars[1::4], chars[2::4], chars[3::4])] return "".join([chr(int(c, 16)) for c in chars]) print(convert(b"6D4B8BD5")) +++++++ #> python test123.py 测试
Second solution without using lists & etc. Easier and faster.
def convert(chars): if isinstance(chars, bytes): chars = chars.decode('ascii') result = '' for i in range(len(chars) // 4): result += chr(int(chars[4 * i:4 * (i + 1)], 16)) return result print(convert(b"6D4B8BD5")) ++++++++ #> python test123.py 测试