When it comes to the types of file formats, there are mainly two types – binary and text. Apparently, the file formats may look similar, but they are different in terms of encoding data. Even though the data are stored in bits, but bits in text files denote characters while that in binary files denote custom data. As a matter of fact, text files contain only textual data while binary files can contain both textual as well as custom binary data. Text files can be of two types named plain text and rich text like font, text color and style files. Binary files can be of various types like audio, images, videos, text and executable files. The following are the differences between text files and binary files.

Storage –

In a text file, the data are stored in the form of characters, digits, special characters by converting them to their respective ASCII value. However, the data are readable when you open them due to instant conversion. Therefore, any small error is instantly detectable and changeable. Examples of text file are TXT, C, and JAVA files.

In a binary file, these characters, digits and special characters stored as a collection of bytes or custom data which are not readable. Therefore, you will find binary files becoming corrupt as the errors cannot be rectified. Examples of binary files are MP3, EXE files. However, the binary files are more secured due to this lack of readability factor.

Number Storage –

In the text mode, the function fprintf() is used for storing numerical data. The characters take one byte as expected while integer should 4 bytes, but it is not the case. It takes 6 bytes instead for a number with 6 digits. Therefore, it treats numbers as characters. Therefore, if your file has a lot of integers, the memory storage will be inefficient as integers are taking as much space as characters which should not be the case.

Due to this anomaly or inefficiency, binary files score over text files. In a binary file, fread and fwrite functions are used, and any number within the range of an integer takes only 4 bytes as it should. Therefore, binary files are highly efficient in most of the cases for storing numbers.

In general, bits represent character in a text file while bits represent a custom data in a binary file.

Encoded –

The inefficiency of text file is due to the fact that the text files are not compressed but encoded in a simple way. Due to the lack of compression, the space taken is more. However, the binary file is always tightly compressed, and the encryption is a result of the same. Therefore, it is more efficient is data storage as well as management. There are loads of possibilities of data storage in doc, pdf, excel files all of which are binary files. As a matter of fact, ZIP and RAR files are binary files.

Newlines –

A newline is end of line or line break. A special character is used to signify a new line. In a text file, this special newline character is converted into a carriage-return combination and stored in the disk. Similarly, when it comes to reading the line break, the conversion is reversed. This takes unnecessary time and space and therefore, it is slightly inefficient in case of large files. In binary files, there is no such conversion required.

End of File –

There is a distinct difference between the representation of the end of file for binary and text file. In the text file, a special character is inserted at the end of the file which is generally ASCII 26th character. In the binary file, there is no use of any special character to denote the end of the file. Instead, it keeps track of the total number of character present in the binary file.

The biggest and the most fundamental difference is that a text file can only store plain text while a binary file can store text, image, audio, and likewise. However, a text file can be opened in almost any simple text editor and special editor. But a binary file needs special applications to open them like media player for audio files, image editor for an image file. On the other hand, EXE files are independent of any application.