Binary file advantages and disadvantages
Input and output are much faster using binary data. Converting a bit integer to characters takes time. Not a great deal of time, but if a file such as an image file contains millions of numbers the accumulated conversion time is significant.
Computer games would slow to a crawl if their data were stored in character form. A binary file is usually very much smaller than a text file that contains an equivalent amount of data. For image, video, and audio data this is important. Small files save storage space, can be transmitted faster, and are processed faster. A DVD would not have room enough to store a movie if the data were stored in character format. Some kinds of data can't easily be represented as characters.
For example, the bytecodes of a Java class file or the machine language of an executable file. You may not usually think of this as data, but of course, it is. The Java compiler reads an input file a source file and writes a binary data file containing its results the bytecode file.
However, the same value can be recorded as a binary value in a number of different ways. For example, given the number , we could store it as individual characters 1 , 2 , 3 , 4 , and 5 , using one byte for each character: This tends to be a less efficient method because it tends to consume more memory, but it has the advantage that the file has a very simple structure. This means that it is very simple to write software to read the file because we know that each byte just needs to be converted to a character.
There may be problems determining data values from the individual characters see Section 7. For the purposes of this book, a binary format is just any format that is not plain text. The characteristic feature of a binary format is that there is not a simple rule for determining how many bits or how many bytes constitute a basic unit of information.
Given a series of, say, four bytes, we cannot assume that these correspond to four characters, or a single four-byte integer, or half of an eight-byte floating-point value see Section 7. It is necessary for there to be a description of the rules for the format we will look at one example soon that state what information is stored and how many bits or bytes are used for each piece of information.
Binary formats are consequently much harder to write software for, which results in there being less software available to do the job. However, some binary formats are easier to read than others. Given that a description is necessary to have any chance of reading a binary file, proprietary formats, where the file format description is kept private, are extremely difficult to deal with.