Question

a program that takes a binary file and opens it and translates the data and prints...

a program that takes a binary file and opens it and translates the data and prints to a new text file. written in python

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
code that will take a binary file and searching for a byte pattern and then print...
code that will take a binary file and searching for a byte pattern and then print to a new text file. code written in python. printing the data from the binary to human legible text. prints data when pattern in found.
Create a Python program that opens and reads a csv file. Display csv file in legible...
Create a Python program that opens and reads a csv file. Display csv file in legible format. Include the program as a function.
Create a Python program that opens and reads an excel file (xlsx). Display excel file in...
Create a Python program that opens and reads an excel file (xlsx). Display excel file in legible format. Include the program as a function.
Write a Python program using that takes a number as input and then prints if the...
Write a Python program using that takes a number as input and then prints if the number is even or odd. The program should use a function isEven that takes a number as a parameter and returns a logical value true if the number is even, false otherwise.
Write a program in python that takes a txt file and converts it to html
Write a program in python that takes a txt file and converts it to html
C++ create a program that: in main: -opens the file provided for input (this file is...
C++ create a program that: in main: -opens the file provided for input (this file is titled 'Lab_HW10_Input.txt' and simply has 1-10, with each number on a new line for 10 lines total) -calls a function to determine how many lines are in the file -creates an array of the proper size -calls a function to read the file and populate the array -calls a function to write out the contents of the array in reverse order *output file should...
python code We're using structs and focusing on binary file I/O def read_attributes(file_path, format): """ Given...
python code We're using structs and focusing on binary file I/O def read_attributes(file_path, format): """ Given a binary file written using struct.pack() with the given format, return the number of bytes in the file and the number of bytes in each chunk. :param file_path: :param format: a string with the format of the data in the struct :return: tuple with the number of bytes in file and the number of bytes written in each chunk """
Write a program in c laungage that prints a table of the binary, octal and hexadecimal...
Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256. Functions are not allowed and built-in functions for octa,binary and hexadecimal are also not allowed.
Create a program that filters the data in a CSV file of product data based on...
Create a program that filters the data in a CSV file of product data based on some search word and prints the resulting output to a new file. Additionally, the program will print the number of items filtered to stdout. • Your program should take three arguments: an input file to process, an output file to save the results, and a search word. • If the output file already exists or cannot be opened, warn the user by printing "CANNOT...
Goals: Write a program that uses binary files. Write a program that stores records to a...
Goals: Write a program that uses binary files. Write a program that stores records to a binary file. C++ Requirements: Write a program that includes a structure named Part that contains the following fields: name - a character array of 20 elements that stores the name of the part. qty - an integer that stores the number of parts in stock. price - a double that stores the price of the part. Create three Part variables in main, and fill...