Python之字符串、字节串、HEX之间互转代码分享
import os
import sys
import datetime
from collections import OrderedDict
import binascii
def main(argv):
print('\n')
input()
class X_conversion(object):
def __init__(self):
self.version = 'V1.0.0'
def hex2bytes(data:bytes):
data_bytes = binascii.unhexlify(data)
return data_bytes
def hex2str(data:bytes):
data_hex_str = data.decode()
return data_hex_str
def str2hex(data:str):
data_hex = data.encode()
return data_hex
def hexstr2bytes(data:str):
data_hex = str2hex(data)
data_hex_bytes = hex2bytes(data_hex)
return data_hex_bytes
def str2bytes(data:str):
data_bytes = data.encode()
return data_bytes
def bytes2hex(data:bytes):
data_hex = binascii.hexlify(data)
return data_hex
def bytes2str(data:bytes):
data_str = data.decode()
return data_str
def bytes2hexstr(data:bytes):
data_hex = bytes2hex(data)
data_hex_str = hex2str(data_hex)
return data_hex_str
if __name__ == "__main__":
main(sys.argv[1:])
《AUTOSAR谱系分解(ETAS工具链)》之总目录