Click to See Complete Forum and Search --> : What function one must use to get checksum of a file?


sulacco
July 15th, 2006, 03:53 PM
Hi, People. How to get checksum of the file using simple win32 or something
functions?
very obliged.

philkr
July 16th, 2006, 05:28 AM
http://en.wikipedia.org/wiki/Cyclic_Redundancy_Check

sulacco
July 17th, 2006, 04:43 PM
Thanks. But that's too heavy for mortal man.

philkr
July 18th, 2006, 08:59 AM
Well, you have to skip the unimportant parts. But maybe a simple example will be better.

The following C program will calculate the CRC-32 of the 8 bit long data stream 10001100:

#include <stdio.h>
#define CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */

int datastream[]={1,0,0,0,1,1,0,0};
int databits=8;

unsigned long crc32; /* Shiftregister */
void calc_crc32(int bit)
{ int hbit=(crc32 & 0x80000000) ? 1 : 0;
if (hbit != bit)
crc32=(crc32<<1) ^ CRC32POLY;
else
crc32=crc32<<1;
crc32 &= 0xffffffff; /* limit to 32 bits */
}
int main()
{ int i;

crc32=0;
for (i=0; i<databits; ++i)
calc_crc32(datastream[i]);
printf("0x%08X",crc32);
}

sulacco
July 18th, 2006, 07:54 PM
Well. That's what I call real German quality!!!

philkr
July 19th, 2006, 05:17 AM
Well. That's what I call real German quality!!!
You're right. Since you didn't like the english wikipedia article, I copied this piece of code from the german one.