Home > Backend Development > PHP Tutorial > The difference between text files and binary files

The difference between text files and binary files

墨辰丷
Release: 2023-03-27 22:14:01
Original
3798 people have browsed it

This article mainly introduces the difference between text files and binary files. Interested friends can refer to it. I hope it will be helpful to everyone.

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, a carriage return is treated as a character '/n' , and the binary mode thinks it is two characters 0x0D, 0x0A; if 0x1B is read in the file, the text mode will think it is the end of file character, that is, the binary model will not process the file, and the text mode will process it according to a certain method to convert the data accordingly. The above is the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

Java implements detailed explanation of the method (string, picture) of parsing

binary file

java implements the method of parsing

binary files

Using Python for

binary filesEasy way to read and write

The above is the detailed content of The difference between text files and binary files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template