Home  >  Article  >  Backend Development  >  Text files and binary files

Text files and binary files

高洛峰
高洛峰Original
2017-02-28 14:58:461852browse

From the perspective of file encoding, files can be divided into two types: ASCII code files and binary code files.

ASCII files are also called text files. When this kind of file is stored on the disk, each character corresponds to one byte, which is used to store the corresponding ASCII code. For example, the storage format of the number 5678 is:

ASC code: 00110101 00110110 00110111 00111000
  ↓   ↓   ↓
Decimal code: 5   6 7 8 occupies a total of 4 bytes. ASCII code files can be displayed character by character on the screen. For example, the source program file is an ASCII file. Use the DOS command TYPE to display the contents of the file. Since it is displayed in characters, the contents of the file can be understood.

Binary files store files in binary encoding.

For example, the storage form of the number 5678 is: 00010110 00101110 only takes up two bytes. Although binary files can be displayed on the screen, their contents cannot be read. When the C system processes these files, it does not distinguish between types. It treats them as character streams and processes them by bytes. The start and end of the input and output character streams are only controlled by the program and are not controlled by physical symbols (such as carriage returns).

So this kind of file is also called "streaming file".

A file can be opened in text mode or binary mode. The difference between the two is: in text mode, the carriage return is regarded as one character '/n', while in binary mode, it is regarded as two characters 0x0D, 0x0A; if 0x1B is read in the file, the text mode will think that this is the end of file character, that is, the binary model will not process the file, and the text mode will convert the data accordingly in a certain way.

The above cliché about the difference between text files and binary files is all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

For more articles related to text files and binary files, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Four ways to mix PHP/HTMLNext article:Four ways to mix PHP/HTML