a
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Crc16.cpp: implementation of the Crc16 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Crc16.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Crc16::Crc16()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// Crc16::~Crc16()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
unsigned short Crc16::table[ 256 ];
|
||||
int Crc16::initialized = 0;
|
||||
|
||||
Crc16::Crc16( unsigned short init_value )
|
||||
{
|
||||
if ( !initialized ) {
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int crc;
|
||||
|
||||
for ( i = 0 ; i < 256 ; i++ ) {
|
||||
k = i << 8;
|
||||
crc = 0;
|
||||
for ( j = 0 ; j < 8 ; j++ ) {
|
||||
if ( ( crc ^ k ) & 0x8000 )
|
||||
crc = ( crc << 1 ) ^ 0x1021;
|
||||
else
|
||||
crc <<= 1;
|
||||
k <<= 1;
|
||||
}
|
||||
table[ i ] = (unsigned short) crc;
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
crc = init_value;
|
||||
}
|
||||
Reference in New Issue
Block a user