【发布时间】:2021-09-19 01:29:21
【问题描述】:
我需要计算从大小为 M(一对 Kb,与我的范围无关)的二进制文件中提取的 N 字节(示例中为 5,为简单起见)的 CRC16。
printf "offset\tvalue\tcrc16\n";
#Read N bytes from file and copy in the container
for my $counter (0 .. 5- 1)
{
my $oneByte;
read(FH, $oneByte, 1) or die "Error reading $inFile!";
my $ctx2 = Digest::CRC->new( type => 'crc16' );
my $digest2 = ($ctx2->add($oneByte))->hexdigest;
# PRINT for debugging
printf "0x%04X\t0x%02X\t0x", $counter, ord $oneByte;
print $digest2, "\n";
}
考虑到这个二进制输入
我得到结果:
脚本正在逐字节执行 CRC16(顺便说一下正确),但我需要 5 个字节的完整二进制流的 CRC16(预期值应该是 0x6CD6)。 脚本哪里错了?
【问题讨论】: