The following is a CRC32 computingCodeAccording to my tests, the results are correct. I hope to help you and avoid detours !!!
Note !!!!
The generated polynomial is: Poly = 0x4c11db7;
Class iso_13818_crc32 {
Public:
Iso_13818_crc32 ();
Void Update (char * data, long length );
Unsigned long get_value ();
PRIVATE:
Void process_byte (unsigned char B );
Unsigned char pump_bit (unsigned char B, int bit_pos );
Void decode_crc (unsigned char bit );
Unsigned long crc_reg;
Unsigned long poly;
};
Iso_13818_crc32: iso_13818_crc32 ()
{
Crc_reg = 0 xffffffff;
Poly = 0x4c11db7;
}
Void iso_13818_crc32: decode_crc (unsigned char bit)
{
Unsigned char add;
Add = (crc_reg & 0x80000000 )? 1: 0) ^ bit; // The highest bit of crc_reg is different from that of bit.
Crc_reg <= 1;
If (ADD ){
Crc_reg ^ = poly;
}
}
Unsigned long iso_13818_crc32: get_value ()
{
Return crc_reg;
}
Void iso_13818_crc32: process_byte (unsigned char B)
{
For (INT I = 0; I <8; I ++ ){
Decode_crc (pump_bit (B, 7-I ));
}
}
Unsigned char iso_13818_crc32: pump_bit (unsigned char B, int bit_pos)
{// Return the 8-bit_pos position of B (from high to low)
If (bit_pos> = 0 & bit_pos <= 7 ){
If (B & (1 <bit_pos )){
Return 1;
}
Else {
Return 0;
}
}
Else {
Return 0;
}
}
Void iso_13818_crc32: Update (char * data, long length)
{
Crc_reg = 0 xffffffff;
For (INT I = 0; I <length; I ++ ){
Process_byte (data [I]);
}
}