Concept

When should data be stored in binary or text file format?

ComputerScienceOne / Binary vs Text Files

"As previously mentioned, files can be stored as pure binary data or as plaintext (ASCII). Depending on our application and the nature of the data being written to files, the choice of which to use may be clear. If we want the data in our files to be human-readable, then we need to store them as plaintext. However, in general, we should prefer storing data in a binary format. The reason for this is that binary generally requires less space and is more efficient to process. Consider as an example, storing a collection of integers in a file. Each integer requires 4 bytes when represented in binary. However, when represented as a string, it requires as many bytes as there are digits in the number. For example, the maximum representable value of such an integer would be 2 31 − 1 = 2 , 147 , 483 , 647, requiring 10 ASCII characters and thus 10 bytes to represent, two and a half times as much memory as with the binary representation. Further, if a lot of numbers are stored, each number (as a string) would need to be delimited by yet another character. With a binary representation, no delimiter would be necessary as we would know that each 4 byte block represents a single number. This disparity can be even more stark with other types such as floating-point numbers."

Related Ideas

When should data be stored in binary or text file format? | ComputerScienceOne | Bifalgorithm | Bifalgorithm