二进制文件和文本文件有什么区别 [英] What is the difference between binary file and text file

查看:87
本文介绍了二进制文件和文本文件有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

二进制文件和文本文件之间的区别是什么?可以在这里提出这样的问题.

无论如何,此处链接" [ ^ ]来回答您的问题.


实际上,这不是100%正确的问题.实际上:所有文件都是二进制文件.这是一种行话:通常,如果一个文件根本不包含任何数值数据表示形式,或者使用人类可读的文本模式"表示此类数据,则该文件称为文本文件.这是一种行话.任何文件实际上都可以包含不同表示形式的混合物.

让我们考虑一个32位整数int value = 0x1234ABCD;.在需要最小的4个字节来写它. (0xCD等).它取决于数据类型,而不取决于值.

同时,您可以将其写为字符串,以十六进制形式"0x1234ABCD"或十进制形式"305441741",10或9个字符组成,每个字符将采用Unicode UTF-8或ASCII编码的1个字节或2个字节UTF-16编码中的单词,长度(如果表示形式)取决于值和格式.例如,比较"12345","3"和"0003".在这种字符串表示的情况下,通常称为文本格式".顺便说一下,十六进制"或十进制"的概念仅与这种文本格式"有关.

还有许多其他形式的数字和其他数据表示形式.我描述的演示方式被更频繁地使用,这就是为什么使用那些令人困惑的术语.它们确实有些令人困惑,许多初学者在使用它们时遇到了一些麻烦.

另请参见: http://en.wikipedia.org/wiki/Text_file [
希望能解释一下.


What is the difference between binary file and text file

Google would have given you an answer more quickly and with less harassment than you''re liable to get for asking a question like this here.

Anyway,
here''s a link[^] to one answer to your question.


This is not a 100% correct question, in fact. In reality: all files are binary. This is a kind of jargon: usually a file is called a text file if does not contain any representations of numeric data at all or such data is represented using human-readable "text mode". This is rather a kind of jargon. Any file can actually contain a mixture of different representation.

Let''s consider a 32-bit integer int value = 0x1234ABCD;. In needs minimal 4 byte to write it. (0xCD, etc.). It depends on the data type and does not depend on the value.

At the same time you can write it as a string in hexadecimal form "0x1234ABCD" or in decimal form as "305441741", 10 or 9 characters, and each character will take 1 byte in Unicode UTF-8 or ASCII encoding or 2-byte words in UTF-16 encoding, and the length if representation depends both on the value and the format. For example, compare "12345", "3" and "0003". In the case of such string representation, it''s usually called "text format". By the way, the notions of "hexadecimal" or "decimal" are relevant only to such "text format".

There is a number of other forms of representations of numeric and other data. The ways of presentation I have described are used more often, that''s why those confusing terms are used. They are really somewhat confusing, many beginners have some troubles with them.

Please see also: http://en.wikipedia.org/wiki/Text_file[^].

—SA


A binary file is treated as raw data and read byte-by-byte. A text file is considered to contain lines of text that are separated by some end-of-line markings. And here is the problem: These end-of-line markings are different depending on the operating system. Unix / Linux etc. use a newline character (''\n''), while DOS and Windows use a two-character sequence of carriage-return plus line-feed (\r\n). By telling the I/O system that a file contains text lines, it can watch out for both types of line separators and deliver the lines to your program in a uniform way. On output it can add the correct line separator to what you write.

Hope that explains it.


这篇关于二进制文件和文本文件有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆