Input Byte array = [b'\x03\x00', b'\x04\x00', b'\x05\x00', b'\x05\x00', b'\x05\x00', b'\x06\x00', b'\x07\x00',
b'\x08\x00', b'\t\x00', b'\n\x00', b'\t\x00', b'\x08\x00', b'\x07\x00', b'\x06\x00']
I need to write the above array to a binary file and to verify if the data is written correctly I am reading back the same file. But While reading back it is giving me an empty list. Can someone point out the error here??
#Values array is calculated from the previous steps
intermediate = [int.from_bytes(x, byteorder='big', signed=True) for x in values]
print("Integer in Big Endian {}".format(intermediate))
fileData = [byte.to_bytes(2, byteorder='little', signed=True) for byte in intermediate]
print("Data written to the Binary file{}".format(fileData))
#I am printing the array of bytes that I am writing to the file.
newFile = open('./flash.dat', "wb")
for byte in intermediate:
newFile.write(byte.to_bytes(2, byteorder='little', signed=True))
file = open("./flash.dat", "rb")
number=file.read()
file.close()
print("Data in the binary file {}".format(number))
The result is this
Integer in Big Endian [3, 4, 5, 5, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6]
Data written to the Binary file[b'\x03\x00', b'\x04\x00', b'\x05\x00', b'\x05\x00', b'\x05\x00', b'\x06\x00',
b'\x07\x00', b'\x08\x00', b'\t\x00', b'\n\x00', b'\t\x00', b'\x08\x00', b'\x07\x00', b'\x06\x00']
Data in the binary file b''