def format_bytes(data: bytes): return ''.join(f'\\x{byte:02X}' for byte in data) if __name__ == '__main__': msg = b'\xaa\x01\x00\x93\x12\x00\xA6' print(format_bytes(msg)) msg = b'\xAA\x01\x00\x95\x00\x00\x96' print(format_bytes(msg))