definitive CRC for C

前端 未结 4 1114
北海茫月
北海茫月 2020-12-05 00:59

Since CRC is so widely used, I\'m surprised by having a hard time finding CRC implementations in C.

Is there a \"definitive\" CRC calculation snippet/algorithm for

4条回答
  •  生来不讨喜
    2020-12-05 01:37

    Not sure about CRC-8 or CRC-16, but there is example CRC-32 code in RFC 1952. This RFC also references the V.42 standard, which describes a CRC-16 in section 8.1.1.6.

    RFC 1952 also states:

            If FHCRC is set, a CRC16 for the gzip header is present,
            immediately before the compressed data. The CRC16 consists
            of the two least significant bytes of the CRC32 for all
            bytes of the gzip header up to and not including the CRC16.
            [The FHCRC bit was never set by versions of gzip up to
            1.2.4, even though it was documented with a different
            meaning in gzip 1.2.4.]
    

    So there's your CRC-16 and CRC-32, potentially. (just take the two least significant bytes of the CRC-32, that is.)

提交回复
热议问题