September 2026
1051 pages
35h 4m
English
When a file is read in binary mode, the file contents arrive in the program as a sequence of bytes. A byte consists of eight bits and thus represents a number between 0 and 255. Values that don’t fit into this number space are represented by a sequence of bytes.
In Chapter 6, Section 6.4.3, we binary-read a graphic in bitmap file format to get the height, width, and color depth of the image. As image dimensions can exceed 255 pixels, the height and width of the image are stored in bitmap format by a sequence of four bytes.
Python's standard library contains the struct module, which takes care of interpreting byte sequences for us. The preceding example can be written using the struct module as follows: ...
Read now
Unlock full access