f = open("test.dat", "rb") b = f.read(1) str = "" while True: b = f.read(1) if b == b'': break str += b.hex() print(str) f.close() except IOError: print('error') 81d182d180d0bed0bad0b0