📄 crc.h
字号:
// ********************** START OF CRC.H **********************
//
// This header file contains the definitions for the two CRC
// classes, Crc16 and Crc32.
//
#ifndef _CRC_DOT_H
#define _CRC_DOT_H
// The two CRC objects create 16 and 32 bit CRC values using the
// polynomials used by ZMODEM. The calculations are table driven,
// with the table being initialized by the constructor at runtime.
// The constructor assigns an initial value to the crc, and then
// it is updated on a character by character basis.
class Crc32 {
private :
static unsigned long table[ 256 ];
static int initialized;
unsigned long crc;
public :
Crc32( unsigned long init_value );
void update( int c );
unsigned long value( void ){ return crc; }
};
inline void Crc32::update( int c )
{
crc = table[ ( (int) crc ^ ( c & 0xff ) ) & 0xff ] ^
( ( crc >> 8 ) & 0x00FFFFFFL );
}
class Crc16 {
private :
static unsigned short table[ 256 ];
static int initialized;
unsigned short crc;
public :
Crc16( unsigned short init_value );
void update( int c );
unsigned short value( void ){ return crc; }
};
inline void Crc16::update( int c )
{
crc = (unsigned short)
( table[ (( crc >> 8 ) & 0xff ) ] ^
( crc << 8 ) ^ ( c & 0xff ) );
}
#endif // #ifndef _CRC_DOT_H
// ************************ END OF CRC.H ************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -