code: def hex_escape(bin_str):
    
    printable = string.ascii_letters + string.digits + string.punctuation + ' '
    return ''.join(ch if ch in printable else r'0x{0:02x}'.format(ord(ch)) for ch in bin_str)
docs: Hex encode a binary string