I am trying to create a bunch of binary files that contain corresponding hex values
for i in range(2**8):
file = open("test" + str(i) + ".bin", "wb")
file.write(hex(i))
file.close()
Unfortunately it appears that a text representation of my counter converted to hex is being written to the files instead of the actual hex values. Can someone please correct this code? I’m sure the problem is with hex(i)
If you want the value to be written in binary, use chr() to create the character from i: