一段C++算法,请高手帮忙编辑成Pascal,谢谢!
#include <stdio.h>
#define SLIDE_ID_LEN 11 // Length of slide ID
// This function computes and returns the CRC associated with the slideIDString input
// argument.
//
unsigned char computeCrc(char *slideIdString)
{
unsigned char Local8BitPoly = 0x025;
unsigned char crcTable[256];
int i,j;
unsigned char crc = 0;
// Generate CRC table
unsigned char crc_accum;
for(i=0; i<256; i++)
{
crc_accum = (unsigned char) i;
for(j=0; j<8; j++)
{ // If lead 1 then XOR to divide else move on.
if(crc_accum & 0x80)
crc_accum = (crc_accum << 1) ^ Local8BitPoly;
else
crc_accum = (crc_accum << 1);
}
crcTable[i] = crc_accum; // Update next item in table
}
// calculate the CRC
for(j=0; j < SLIDE_ID_LEN; j++)
{
i = ((crc) ^ slideIdString[j]) & 0xff;
crc = (crc << 8) ^ crcTable[i];
}
return crc;
}
// This main program provides an example of how to use the computeCrc function.
// In this example, the CRC's are computed and displayed for a range of 25 ID's starting
// with the ID value of "140180001".
//
int main(int argc, char* argv[])
{
long id = 140180001;
char idstring[SLIDE_ID_LEN+1];
int i;
// Generate CRC for 25 values
for (i=0; i < 25; i++, id++)
{
sprintf(idstring, "%011d", id);
printf("%s %03d\n", idstring, computeCrc(idstring));
}
return 0;
}