From anonymous, 2 Months ago, written in Python.
Embed
  1. def repr_like(ba):
  2.     out = []
  3.     for b in ba:
  4.         if 0x20 <= b < 0x7f:
  5.             out.append(chr(b))
  6.         else:
  7.             out.append(f"\\x{b:02x}")
  8.     return "".join(out)
  9.  
  10.  
  11. ba = bytearray(b'\x02|CC|1|E|33||||||||bap||||1|\x03I')
  12. print(repr_like(ba))
  13. print(repr(ba))
  14.