python3 bytes与hex_string之间的转换

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)
原文地址:https://www.cnblogs.com/z-joshua/p/7170026.html