我有一個名為 hello.txt 的檔案,其內容如下:
hello
當我像這樣對該檔案執行 linux crc32 時:(我通過 sudo apt install libarchive-zip-perl 安裝)
crc32 hello.txt
我得到:
363a3020
當我想使用一些在線計算器或 npm 庫(來自 node.js 的 crc)時,我只在文本上執行它并得到以下結果:
3610a686
這是不同的。我怎樣才能檢查這個,以便結果是一樣的?這里有什么區別?有人可以解釋嗎?
uj5u.com熱心網友回復:
看起來好像您通過運行以下內容創建了檔案:
echo hello > hello.txt
echo 命令附加一個換行符,因此該檔案的內容實際上是hello<newline>. 我們可以使用 hexdump 工具看到這一點,例如:
$ od --endian=big -x hello.txt
0000000 6865 6c6c 6f0a
0000006
或者只計算位元組數:
$ wc -c hello.txt
6 hello.txt
在這里,我們看到它是 6 個位元組,而不是預期的 5 個位元組。如果我們禁止終端換行:
echo -n hello > hello.txt
然后我們得到預期的 crc:
$ crc32 hello.txt
3610a686
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/450004.html
