1, bytes to hex_string的转换:

def byte_to_hex(bins):
"""
Convert a byte string to it's hex string representation e.g. for output.
""" return ''.join( [ "%02X" % x for x in bins ] ).strip()

2, hex_string to bytes的转换:

def hex_to_byte(hexStr):
"""
Convert a string hex byte values into a byte string. The Hex Byte values may
or may not be space separated.
""" return bytes.fromhex(hexstr)
05-11 21:52