文本和二进制文件混淆 [英] text and binary files confusion

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

问题描述

朋友们,


我已经有这种混乱大约一年了,我想知道

文本和二进制之间的确切区别文件。


使用c中的fwrite函数,我用二进制

模式写了2个字节的整数。

据我说,记事本打开文件和文件的每个字节

读取,它将该字节从ascii转换为正确的字符并且

显示

it on屏幕..

这就是我做的,我用fwrite写了2个字节(一个整数)和

因为ascii

是1个字节,我希望在记事本中显示2个字符..

第一个字符正确显示但不是第二个字符。


加入我的混乱文本和二进制文件,在Linux上运行的一些FTP服务器需要以''ascii模式''和二进制

文件的'二进制模式'上传html文件。

这两个都是由sequ组成的普通文件ential系列字节

毕竟,然后

为什么是单独的模式?

任何洞察这种混乱的人都会非常感激。


非常感谢你的时间。


- joel

解决方案

在2006-03-13, jo*******@gmail.com < ;乔******* @ gmail.com>写道:

嗨朋友们,

我一直有这种困惑大约一年,我想知道文本和二进制文件之间的确切区别使用c中的fwrite函数,我用二进制
模式写了2个字节的整数。
据我说,记事本打开文件和文件的每个字节
读取,它将该字节从ascii转换为正确的字符,然后在屏幕上显示它。
这就是我所做的,我写了2个字节(一个整数)使用fwrite和
因为ascii
是1个字节,我希望在记事本中显示2个字符。
第一个字符显示正确而不是第二个。

加上我对文本和二进制文件的混淆,在Linux上运行的一些FTP服务器需要以''ascii模式''和'二进制模式''上传html文件和'二进制
文件'。
两者都是普通文件,包括一系列连续的字节
毕竟,然后
为什么选择单独的模式?

我们将非常感谢您对这种困惑的任何见解。

非常感谢您的时间。

- joel




首先,不要担心:这是让很多人绊倒的事情。


我准备写一个几行,然后决定不这样做因为(a)我不能想到这样做的雄辩方式和(b)像大多数事情一样,

其他人做过它首先。成为优秀工程师的秘诀

并不是如何做某事,而是知道可能有更好的方式,并且知道如何找到更好的方法: - ;


这里:

http://en.wikipedia.org/wiki/Binary_and_text_files

有一个关键部分可能会让你感到困惑(不知道你的

熟悉ascii文本),那就是:


"文本文件是大多数字节(或短字节序列)的文件

代表普通文件可读字符,如字母,


短字节序列很重要:google up unicode和dbcs。


-

调试器:你知道它是有道理的。
http://heather.cs.ucdavis.edu/~matlo...g.html#tth_s Ec


Le 13-03-2006, jo * ******@gmail.com < jo ******* @ gmail.com> écrit*:

我一直有这种困惑大约一年,我想知道文本和二进制文件之间的确切区别。


据我所知,主要区别在于''\ n''字符的解释



In文本模式,''\\ n''是一个''行尾''指示,将
映射到''\ n'',''\\ n''或''\ r''取决于文件系统

编码行尾。

在二进制模式下,''\\ n'''是''\\ \\ n''。

使用c中的fwrite函数,我在二进制
模式下写了2个字节的整数。
据我说,记事本打开文件和每个字节的文件
读取,它将该字节从ascii转换为正确的字符并在屏幕上显示
..


假设您的编码是ASCII ,是的。

所以'我做了什么,我用fwrite写了2个字节(一个整数)和
因为ascii
是1个字节,我预计2个字符到在记事本中显示..
正确显示第一个字符不是第二个。




也许它不是''可显示''的价值。


Marc Boyer


>也许这不是一个''可显示'的价值。


值可以显示,因为ascii代码

i以二进制文件写入文件:

40H

和41H

2字节。

我预计它会显示AB

但它显示了A @


这让我感到困惑..


- joel


hi friends,

i''ve been having this confusion for about a year, i want to know the
exact difference between text and binary files.

using the fwrite function in c, i wrote 2 bytes of integers in binary
mode.
according to me, notepad opens files and each byte of the file
read, it converts that byte from ascii to its correct character and
displays
it on screen..
so that''s what i did, i wrote 2 bytes (an integer) using fwrite and
since ascii
is 1 byte, i expected 2 characters to be displayed in notepad..
the first character displayed correctly but not the second.

to add to my confusion of text and binary, some FTP servers running
on Linux require html files to be uploaded in ''ascii mode'' and binary
files in ''binary mode''.
Both are ordinary files consisting of a sequential series of bytes
after all, then
why a seperate mode?
Any insight into this confusion would be greatly appreciated.

thanks a lot for your time.

- joel

解决方案

On 2006-03-13, jo*******@gmail.com <jo*******@gmail.com> wrote:

hi friends,

i''ve been having this confusion for about a year, i want to know the
exact difference between text and binary files.

using the fwrite function in c, i wrote 2 bytes of integers in binary
mode.
according to me, notepad opens files and each byte of the file
read, it converts that byte from ascii to its correct character and
displays
it on screen..
so that''s what i did, i wrote 2 bytes (an integer) using fwrite and
since ascii
is 1 byte, i expected 2 characters to be displayed in notepad..
the first character displayed correctly but not the second.

to add to my confusion of text and binary, some FTP servers running
on Linux require html files to be uploaded in ''ascii mode'' and binary
files in ''binary mode''.
Both are ordinary files consisting of a sequential series of bytes
after all, then
why a seperate mode?
Any insight into this confusion would be greatly appreciated.

thanks a lot for your time.

- joel



Firstly, dont worry : this is something that trips a lot of people up.

I was about to pen a few lines and then decided not to because (a) I
could not think of an eloquent way of doing it and (b) like most things,
someone else has done it first. The secret of being a great engineer
is not howing how to do something, but knowing that there may be a
better way and knowing how to locate that better way :-;

Here:

http://en.wikipedia.org/wiki/Binary_and_text_files

There is one key part which might confuse you (not knowing your
familiarity with ascii text) and that is:

"Text files are files where most bytes (or short sequences of bytes)
represent ordinary readable characters such as letters,"

The short sequence of bytes is important : google up unicode and dbcs.

--
Debuggers : you know it makes sense.
http://heather.cs.ucdavis.edu/~matlo...g.html#tth_sEc


Le 13-03-2006, jo*******@gmail.com <jo*******@gmail.com> a écrit*:

i''ve been having this confusion for about a year, i want to know the
exact difference between text and binary files.
To my knowledge, the main difference is the interpretation
of the ''\n'' character.
In text mode, ''\n'' is an ''end of line'' indication, mapped
into ''\n'', ''\r\n'' or ''\r'' depending of the file system
encoding of the end of line.
In binary mode, ''\n'' is ''\n''.
using the fwrite function in c, i wrote 2 bytes of integers in binary
mode.
according to me, notepad opens files and each byte of the file
read, it converts that byte from ascii to its correct character and
displays
it on screen..
Assuming that your encoding is ASCII, yes.
so that''s what i did, i wrote 2 bytes (an integer) using fwrite and
since ascii
is 1 byte, i expected 2 characters to be displayed in notepad..
the first character displayed correctly but not the second.



Perhaps it was not a ''displayable'' value.

Marc Boyer


> Perhaps it was not a ''displayable'' value.

the value was displayable im sure, because the ascii codes
i wrote in binary to the file were:
40H
and 41H
2 bytes.
and i expected it to display AB
but it displayed A@

That''s what confuses me..

- joel


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

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