a program that takes a binary file and opens it and translates the data and prints to a new text file. written in python
For this I had downloaded a bin file online.i dont know about the data inside the bin file.
The file contains a list of numbers .
The name of the file is "sample.txt" placed inside the same folder as that of the program.
The code will simply open a bin file and reads the file saving all the data inside the bin file to a list
and then the list will be printed to a text file named "binwrite.txt" wher the data is printed line by line.
Provide the correctfile path for both the bin file and text file.
Code:
#Opening bin file to read
fr=open("sample.bin","rb")
#Opening text file to write
fw=open("binwrite.txt","w")
#reading the binary data converting it and placing them in a list
num=list(fr.read())
#writing the data to the txt file line by line
for i in num:
fw.write(str(i)+"\n")
#closing the read file
fr.close()
#closing the write file
fw.close()
if the code is executed all the data inside the bin file will be converted and added to the text file
Get Answers For Free
Most questions answered within 1 hours.