US-ASCII 编码包含奇数和偶数?
我将数字 1-100 的列表拆分为 2 个字节的文件。然后,我注意到每个奇数 btw 11-99 需要 2 个文件,即 4 个字节,而每个偶数 btw 11-99 需要 1 个文件,2 个字节。一个文件足以容纳 1-10 的数字。您可以确认以下发现。
您如何解释这一发现?
我做了什么?
将数字保存到文件中,就像在 VIM 中一样:
:%!python -c "for i in range(1,100): print i"
:w! list_0_100
使用 Coreutils 中的 GNU Split-命令将文件拆分为 2 个字节的文件:
$ split -b2 -d list_0_100
发现: 每个奇数顺便说一句,11-99只需要两个文件,即4字节。相反,11-99 之间的每个偶数都需要一个文件,即 2 个字节:
$ head x*
==> x07 <==
8
==> x08 <==
9
==> x09 <==
10
==> x10 <==
1
==> x11 <==
1
==> x12 <==
12
==> x13 <==
1
==> x14 <==
3
==> x15 <==
14
==> x16 <==
1
==> x17 <==
5
I splitted the list of numbers 1-100 to files of 2 bytes. Then, I noticed that each odd number btw 11-99 needs 2 files, ie 4bytes, while each even number btw 11-99 needs 1 file, 2bytes. A file is enough for numbers btw 1-10. You can confirm the finding below.
How can you explain the finding?
What did I do?
save numbers to a file, like in VIM:
:%!python -c "for i in range(1,100): print i"
:w! list_0_100
split the file to 2 bytes' files with the GNU Split-command in Coreutils:
$ split -b2 -d list_0_100
Finding: Each odd number btw 11-99 needs only two files, ie 4bytes. In contrast, each even number btw 11-99 needs one file, ie 2bytes:
$ head x*
==> x07 <==
8
==> x08 <==
9
==> x09 <==
10
==> x10 <==
1
==> x11 <==
1
==> x12 <==
12
==> x13 <==
1
==> x14 <==
3
==> x15 <==
14
==> x16 <==
1
==> x17 <==
5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个大于 9 的数字需要三个字节(每个数字一个字节,新行多一个字节)。写入 _ 而不是换行符(为了可见性),您将得到以下结果:
拆分后:
偶数恰好位于一个文件中,但奇数被拆分为两个文件。
Each number greater than 9 requires three bytes (one byte for each digit, and one more byte for the new line). Writing _ instead of the new line character (for visibility) you have this:
After the split:
The even numbers happen to lie in one file, but the odd number get split over two files.