Binary Files
Binary Files
1. Write a program to read data from a binary file and display it on the console.
6. Write a C++ program to split a binary file into parts of 5 KB each. Use the name-00
format to call each part of the file.
7. Write a program in C++ that inverts all the bytes of a binary file. The new file has the
same name with the original file but with the extension .inv.
8. Create a hexadecimal viewer in C++ that shows the contents of a binary file on screen
with 16 bytes per row. The 16 bytes will be displayed first in hexadecimal and then as
printable characters. You must also substitute bytes smaller than 32 (unprintable
characters) with dots. Sample output is given below:
1. 00000000 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ?.........ÿÿ..
2. 00000010 b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ¸.......@.......
3. 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
4. 00000030 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 ............?...
5. 00000040 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68 ..º..´.Í!¸.LÍ!Th
6. 00000050 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f is program canno
9. Write a C++ function to read ID3 v1 tag from an MP3 music file and print it to console.
Below is the structure of ID3 version 1:
It consists of attaching a block of fixed size of 128 bytes at the end of the file in
question. This block contains the following tags:
a. An identification header with the characters "TAG".
b. Title: 30 characters.
c. Artist: 30 characters.
d. Album: 30 characters.
e. Year: 4 characters.
f. One comment: 30 characters.
g. Genre (musical): a character.
All tags use ASCII characters, except the genre, which is an integer stored in a single
byte. The musical genre associated with each byte is predefined in the standard and
includes definitions of 80 genres, numbered from 0 to 79. Certain reproduction
programs have expanded on their own the defined genres (from number 80).
10. Write a program in C++ to read the dimensions of an image in Windows bitmap format.
Description of the BMP file can be viewed here:
https://www.fileformat.info/format/bmp/corion.htm
Firstly, you should first check that it is a valid .bmp image, reviewing the header data
'BM'. If it is a valid .bmp image then it obtained its dimensions (width x height) and
display them on the screen.
Sample BMP file can be downloaded here:
https://www.fileformat.info/format/bmp/sample/index.htm