few*_*few 1 linux crc32 checksum crc
我有一个名为 hello.txt 的文件,其中包含以下内容:
hello
Run Code Online (Sandbox Code Playgroud)
当我在该文件上执行 linux crc32 时,如下所示:(我通过 sudo apt install libarchive-zip-perl 安装)
crc32 hello.txt
Run Code Online (Sandbox Code Playgroud)
我得到:
363a3020
Run Code Online (Sandbox Code Playgroud)
当我想使用一些在线计算器或 npm 库(来自 node.js 的 crc)时,我仅在文本上执行并得到以下结果:
3610a686
Run Code Online (Sandbox Code Playgroud)
这是不同的。我怎样才能检查这个结果是否相同?这里有什么区别?有人可以解释一下吗?
看起来好像您通过运行以下命令创建了该文件:
echo hello > hello.txt
Run Code Online (Sandbox Code Playgroud)
echo 命令附加一个换行符,因此该文件的内容实际上是hello<newline>
. 我们可以使用 hexdump 工具看到这一点,例如:
$ od --endian=big -x hello.txt
0000000 6865 6c6c 6f0a
0000006
Run Code Online (Sandbox Code Playgroud)
或者只计算字节数:
$ wc -c hello.txt
6 hello.txt
Run Code Online (Sandbox Code Playgroud)
在这里我们看到它是 6 个字节,而不是预期的 5 个字节。如果我们抑制终端换行符:
echo -n hello > hello.txt
Run Code Online (Sandbox Code Playgroud)
然后我们得到预期的 crc:
$ crc32 hello.txt
3610a686
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
768 次 |
最近记录: |