You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
discussed in #66 but the original analysis was incorrect because it did not actually test the case where 0 is the previous value.
Ruby code:
require'zlib'puts("no initial value : #{(Zlib::crc32('1')).to_s(16)}")# no initial value : 83dcefb7puts("with initial value : #{Zlib::crc32('1',0).to_s(16)}")# with initial value : 83dcefb7
constCRC32=require('crc-32');console.log(`no initial value : ${(CRC32.bstr('1')>>>0).toString(16)}`);// no initial value : 83dcefb7console.log(`with initial value : ${(CRC32.bstr('1',0)>>>0).toString(16)}`);// with initial value : 83dcefb7
Using crc:
const{crc32}=require('crc');console.log(`no initial value : ${crc32('1').toString(16)}`);// no initial value : 83dcefb7console.log(`with initial value : ${crc32('1',0).toString(16)}`);// with initial value : ae21ffc5
The error is in the special 0 case, which probably stems from a misinterpretation of the english description.
The proper CRC pre and post
conditioning is used, meaning that the CRC register
is pre-conditioned with all ones (a starting value
of 0xffffffff) and the value is post-conditioned by
taking the one's complement of the CRC residual.
Some developers misinterpret that to mean the seed starts at -1. but it's actually saying that the crc variable starts at -1:
constcrc32: CRCCalculator<Uint8Array>=(current,previous)=>{// eslint-disable-next-line @typescript-eslint/no-non-null-assertionletcrc=previous===0 ? 0 : ~~previous!^-1;// ^^^^ This `crc` variable is the "CRC register"for(letindex=0;index<current.length;index++){crc=TABLE[(crc^current[index])&0xff]^(crc>>>8);}returncrc^-1;};
There is no need to special-case the 0, and the TS code might as well be simplified to:
constcrc32: CRCCalculator<Uint8Array>=(current,previous=0)=>{letcrc=previous^-1;// no need to coerce to 32 bit signed intfor(letindex=0;index<current.length;index++){crc=TABLE[(crc^current[index])&0xff]^(crc>>>8);}returncrc^-1;};
The text was updated successfully, but these errors were encountered:
The website cited in the other issue uses the phrase "Initial Value" at the top of the page and the phrase "Initial CRC value" in the Description, so it's easy to see how @alexgorbatchev misinterpreted the default case.
discussed in #66 but the original analysis was incorrect because it did not actually test the case where 0 is the previous value.
Ruby code:
Using
crc-32
:Using
crc
:The error is in the special 0 case, which probably stems from a misinterpretation of the english description.
The APPNOTE.TXT specification states:
Some developers misinterpret that to mean the seed starts at -1. but it's actually saying that the
crc
variable starts at -1:There is no need to special-case the 0, and the TS code might as well be simplified to:
The text was updated successfully, but these errors were encountered: