python进制转换|ASCII字符串
作者:YXN-python 阅读量:4 发布日期:2024-09-14
# ASCII字符串转16进制
def ascii_to_hex(ascii_str):
return ascii_str.encode('utf-8').hex()
# 16进制转ASCII字符串
def hex_to_ascii(hex_str):
return bytes.fromhex(hex_str).decode('ASCII')
# 16进制转二进制数据
def hex_to_bin(hex_str):
return bin(int(hex_str, 16))[2:].zfill(len(hex_str) * 4)
# 二进制数据转16进制
def bin_to_hex(bin_str):
return hex(int(bin_str, 2))[2:]
YXN-python
2024-09-14