The difference between a text file and a binary file

Source: Internet
Author: User

From the file encoding method, the file can be divided into ASCII code files and binary code file two kinds.

ASCII files are also referred to as text files, which are stored on disk with one byte per character for the corresponding ASCII code. For example, the number 5678 is stored in the following form:
ASC code: 00110101 00110110 00110111 00111000
↓↓↓↓
Decimal code: 5 6 7 8 A total of 4 bytes. ASCII files can be displayed on the screen by characters, such as the source program file is an ASCII file, with the DOS command type to display the contents of the file. Because it is displayed by character, it can read the contents of the file.

Binary files are stored as binary encoding methods for storing files. For example, the number 5678 is stored in the form: 00010110 00101110 is only two bytes. Binary files can also be displayed on the screen, but their contents are unreadable. When processing these files, the C system does not distinguish between types, which are treated as character streams and processed in bytes. The start and end of a stream of input and output characters is controlled only by program control and not by physical symbols such as carriage returns. Therefore, this file is also referred to as a "streaming file".

A file can be opened in text or binary mode, where the difference is that the carriage return is treated as a character '/n ' in text mode, while the binary mode considers it to be two characters 0x0d,0x0a; if you read 0x1b in a file, the text pattern will consider it a file terminator, That is, the binary model does not process the file, and the text is converted to the data in a certain way.

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.