def str_to_hex(s):
"""
字符串 转 16进制
:param s:
:return:
"""
return ' '.join([c.encode().hex() for c in s])
def hex_to_str(s):
"""
16进制转 str
:param s:
:return:
"""
return bytes.fromhex(s).decode()
本文介绍了如何使用Python进行字符串与十六进制之间的相互转换,包括详细的代码实现和功能说明,适用于需要处理字符编码的开发者。
def str_to_hex(s):
"""
字符串 转 16进制
:param s:
:return:
"""
return ' '.join([c.encode().hex() for c in s])
def hex_to_str(s):
"""
16进制转 str
:param s:
:return:
"""
return bytes.fromhex(s).decode()
1万+
1086
4577

被折叠的 条评论
为什么被折叠?