输入:
'0x0 0x48 0x65 0x6c 0x6c 0x6f 0x8E 0x21'
输出:
Hello!
当前解决方案:
s = []
birary_data = '0x0 0x48 0x65 0x6c 0x6c 0x6f 0x8E 0x21'.replace(' ', '').split('0x')
for c in birary_data:
if len(c) > 1:
s.append(bytes.fromhex(c).decode('utf-8', 'ignore'))
print("".join(s))
需要帮助:
请问有人可以提出更优雅的解决方案吗?
尝试这个:
data = '0x0 0x48 0x65 0x6c 0x6c 0x6f 0x8E 0x21'
string = "".join([chr(int(item, 16)) for item in data.split()])
print(string)
输出:
Hello!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句