Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between text file and binary file

Why should we distinguish between text file and binary files when transmitting them? Why there are some channels designed only for textual data? At the bottom level, they are all bits.

like image 800
andrew Avatar asked May 18 '11 01:05

andrew


People also ask

What is the difference between binary file and text file in C?

The major difference between these two is that a text file contains textual information in the form of alphabets, digits and special characters or symbols. On the other hand, a binary file contains bytes or a compiled version of a text file.

What is the difference between text and binary files class 12?

Binary file contains the data in the form of 0 and 1(series of binary values) and text files contains the data in the form of stream of characters.In general binary files are identified as executable files. But binary files are not in readable form as like text file.

What is the difference between a text file and a binary file and provide a use case scenario that binary file is technically an advantage in such situation?

Both file types store data in series of bits (binary values of 1s and 0s). Bits in text file represent characters, while bits in binary files represent special files such as images and videos etc. The format of the data you want to store in binary files depends on the software developer's design.

Why are binary files better than text files?

Text files are used to store data more user friendly. Binary files are used to store data more compactly. In the text file, a special character whose ASCII value is 26 inserted after the last character to mark the end of file. In the binary file no such character is present.


2 Answers

At the bottom level, they are all bits... true. However, some transmission channels have seven bits per byte, and other transmission channels have eight bits per byte. If you transmit ASCII text over a seven-bit channel, then all is fine. Binary data gets mangled.

Additionally, different systems use different conventions for line endings: LF and CRLF are common, but some systems use CR or NEL. A text transmission mode will convert line endings automatically, which will damage binary files.

However, this is all mostly of historical interest these days. Most transmission channels are eight bit (such as HTTP) and most users are fine with whatever line ending they get.

Some examples of 7-bit channels: SMTP (nominally, without extensions), SMS, Telnet, some serial connections. The internet wasn't always built on TCP/IP, and it shows.

Additionally, the HTTP spec states that,

When in canonical form, media subtypes of the "text" type use CRLF as the text line break. HTTP relaxes this requirement and allows the transport of text media with plain CR or LF alone representing a line break when it is done consistently for an entire entity-body.

like image 75
Dietrich Epp Avatar answered Nov 01 '22 05:11

Dietrich Epp


All files are saved in one of two file formats - binary or text. The two file types may look the same on the surface, but their internal structures are different.

While both binary and text files contain data stored as a series of (bits (binary values of 1s and 0s), the bits in text files represent characters, while the bits in binary files represent custom data.

like image 30
munendra Avatar answered Nov 01 '22 03:11

munendra