Skip to content

Computer Science · Ch 2 — File Handling in Python

Binary Files

2.2.2

Binary Files

Binary files store data as a sequence of bytes (0s and 1s), just like text files. The critical difference is what those bytes represent. In a text file, each byte corresponds to the ASCII value of a character. In a binary file, the bytes represent the actual content of the file — the raw data of an image, an audio track, a video, a compressed archive, or an executable program.

Because the bytes do not map to readable characters, binary files are not human readable. If you try to open a binary file with a simple text editor, you will see a screen full of garbage symbols. To read or write the contents of a binary file, you need specific software that understands the file's format — for example, a media player for an audio file or an image viewer for a photograph.

Binary files are stored as a continuous sequence of bytes. This makes them fragile: even a single bit change can corrupt the entire file and make it unreadable to the application that created it. Furthermore, because the stored content is not human readable, it is very difficult to locate and fix any error that occurs in a binary file. …