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)

 

posted on 2017-07-14 14:10  _Joshua  阅读(568)  评论(0)    收藏  举报

导航