A file is a series of bytes.
Each byte is an 8-bit integer.
Treating files as binary files simply means you are reading/writing those bytes directly, rather than having them abstracted through a textual interface. But in a sense, all files (even text files) are binary files and can be treated as such.
For example, let's say you have the below text file:
If you examined this file in a hex editor (ie: a program which reads and displays files as raw data) you might see this:
|
68 65 6C 6C 6F 0D 0A 74 68 65 72 65
|
The first 5 bytes (68 65 6C 6C 6F) are the ASCII values for the string "hello"
0D is the value for the '\r' (carriage return)
0A is the value for the '\n' (line feed)
and the last 5 bytes (74 68 65 72 65) are the ASCII values for "there"
Since bytes are nothing but numbers, binary files often store numerical information as bytes, rather than as text. For example, if you save the number "15000" to a text file, it would look something like this:
31 35 30 30 30
- The ASCII values for '1', '5', and '0'
Whereas a binary file (little endian, int = 4 bytes) might store it like this:
The reason for this is because 15000 represented in hex is 0x3A98. On little endian machines, the low byte (98) is store first, follow by increasingly more significant bytes.