dtb_driver
游客
游客
阅读:1248回复:2

C语言的CRC算法?

楼主#
更多 发布于:2002-04-16 14:01
那位大侠有C语言的CRC算法提供?谢谢.交个朋友吧.

请联系:dtb_xinarem6@sina.com
icesoft
驱动牛犊
驱动牛犊
  • 注册日期2002-01-12
  • 最后登录2002-06-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-04-16 21:25
您打算用哪种CRC?一般教材中的模二除法,还是CRC查找表?
icesoft
驱动牛犊
驱动牛犊
  • 注册日期2002-01-12
  • 最后登录2002-06-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于: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;
        }
    }
}

游客

返回顶部