Text files and binary files

Source: Internet
Author: User
The following is an example of the differences between text files and binary files. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the file encoding method. files can be divided into two types: ASCII code files and binary code files.

An ASCII file is also called a text file. when a file is stored on a disk, each character corresponds to one byte and is used to store the corresponding ASCII code. For example, the storage format of hundreds of thousands is:

ASC: 00110101 00110110 00110111 00111000

Decimal Code: 5 6 7 8 occupies 4 bytes in total. The ASCII code file can be displayed by characters on the screen. for example, the source code file is an ASCII file, and the doscommand TYPE can be used to display the file content. Because it is displayed by characters, you can read the file content.

Binary files are stored in binary encoding.

For example, the storage format of hundreds of thousands is: 5678 00010110 occupies only two bytes. Although a binary file can be displayed on the screen, its content cannot be understood. When processing these files, the C system treats them as byte streams and does not differentiate the types. The start and end of the input and output streams are only controlled by the program, not by physical symbols (such as carriage returns.

Therefore, this type of file is also called a "streaming file ".

A file can be opened in text or binary mode. The difference between the two is that in text mode, carriage return is treated as a character '/N ', the binary mode considers it to be two characters: 0x0D and 0x0A. if you read 0x1B in the file, the text mode considers it to be the file terminator, that is, the binary model does not process the file, the text method converts the data in a certain way.

The difference between a text file and a binary file is the full content shared by the editor. I hope to give you a reference and support for PHP.

For more articles about text files and binary files, follow the PHP Chinese website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.