#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;
}
// 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;
}
解决方案 »
- API高手请进,询问如果得到程序外观!顶就有分!!!!
- 本淫的困惑!哪种皮肤可以同时让VC和Inno Setup支持,并且能自己制作编辑?
- 执行储存过程中出现运行的错误,前台如何运用事务进行回滚??
- 求救sql语句怎么写
- 如何在Delphi中测试Delphi自代的函数。(像在vb中测试vb自代的函数)
- 怎样设置wwBGrid页脚上的合计字段?
- left join 导致的dbgrid错误,请看内容,非常急,请指教!!!
- 请装有瑞星杀毒软件的人帮个忙!
- 判断Image中是否有图片应该怎么做啊?
- 请教,LISTVIEW的STYLE设置为REPORT,共4个COLUMNS,如何取得某行某列的节点文字????
- 应用程序移植问题
- [超级难题]XP更改计算机名_别说SetComputerName,那个改的是NETBIOS的名字
SysUtils;const
SLIDE_ID_LEN = 11; // Length of slide IDfunction computeCrc(slideIdString: PChar): Byte;
var
Local8BitPoly: Byte;
crcTable: array[0..255] of Byte;
i, j: Integer;
crc_accum: Byte;
begin
Result := 0;
Local8BitPoly := $025;
// Generate CRC table
for i := 0 to 255 do
begin
crc_accum := Byte(i);
for j := 0 to 7 do
begin
// If lead 1 then XOR to divide else move on.
if crc_accum and $80 <> 0 then
crc_accum := Byte((crc_accum shl 1) xor Local8BitPoly)
else crc_accum := (crc_accum shl 1);
end;
crcTable[i] := crc_accum; // Update next item in table
end; // calculate the CRC
for j := 0 to SLIDE_ID_LEN - 1 do
begin
i := (Result xor Byte(slideIdString[j])) and $ff;
Result := Byte((Result shl 8) xor crcTable[i]);
end;
end;var
id: Longint = 140180001;
idstring: array [0..SLIDE_ID_LEN - 1] of Char;
i: Integer;begin
// Generate CRC for 25 values
for i := 0 to 24 do
begin
SysUtils.FormatBuf(idstring[0], SizeOf(idstring), '%.11d', 5, [id]);
Writeln(Format('%s %.3d', [idstring, computeCrc(idstring)]));
Inc(id);
end;
Readln;
end.