51 lines
1.0 KiB
C++
51 lines
1.0 KiB
C++
// Crc32.cpp: implementation of the Crc32 class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
#include "Crc32.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Crc32::Crc32()
|
|
// {
|
|
//
|
|
// }
|
|
//
|
|
// Crc32::~Crc32()
|
|
// {
|
|
//
|
|
// }
|
|
|
|
unsigned long Crc32::table[ 256 ];
|
|
int Crc32::initialized = 0;
|
|
|
|
Crc32::Crc32( unsigned long init_value )
|
|
{
|
|
if ( !initialized ) {
|
|
int i;
|
|
int j;
|
|
unsigned long coeff;
|
|
|
|
for ( i = 0; i < 256 ; i++ ) {
|
|
coeff = i;
|
|
for ( j = 0; j < 8; j++ ) {
|
|
if ( coeff & 1 )
|
|
coeff = ( coeff >> 1 ) ^ 0xEDB88320L;
|
|
else
|
|
coeff >>= 1;
|
|
}
|
|
table[ i ] = coeff;
|
|
}
|
|
initialized = 1;
|
|
}
|
|
crc = init_value;
|
|
} |