阅读:1284回复:2
C语言的CRC算法?
那位大侠有C语言的CRC算法提供?谢谢.交个朋友吧.
请联系:dtb_xinarem6@sina.com |
|
沙发#
发布于:2002-04-16 21:25
您打算用哪种CRC?一般教材中的模二除法,还是CRC查找表?
|
|
板凳#
发布于:2002-04-16 21:29
先给您一个例子,有其它需要再说吧。
//------------------------------------------------------------------------ // Copyright (C) Sewell Development Corporation, 1994 - 2000. // Web: www.sewelld.com E-mail: support@sewelld.com // // LICENSE: This source code was generated by CrcGen, a product of Sewell // Development Corporation. Paid-up licensees of CrcGen are authorized to // use this code on a site-wide basis without restriction as to // the type of product it is incorporated in, except that it may not be // resold as stand-alone CRC code, and the copyright notice and license // agreement must not be removed from the code. //------------------------------------------------------------------------ #include \"Crc32.h\" // Implementation of 32-bit CRC (cyclic redundancy check) class: // Polynomial: 04C11DB7 // Initial CRC register value: FFFFFFFF // Reflected input and output: No // Inverted final output: No // CRC of string \"123456789\": 0376E6E7 void Crc32::Compute(const void* buffer, unsigned int count) { const unsigned char* ptr = (const unsigned char *) buffer; while (count--) { Compute(*ptr++); } } void Crc32::Compute(unsigned char value) { m_crc ^= ((unsigned __int32)value << 24); for (int i = 0; i < 8; i++) { if (m_crc & 0x80000000) { m_crc = (m_crc << 1) ^ 0x04C11DB7; } else { m_crc <<= 1; } } } |
|