J
Jj1985
Unregistered / Unconfirmed
GUEST, unregistred user!
C++:
crc_data(char *buf, int len)
{
int i, j;
unsigned int crc = 0;
for(i = 0;
i < len;
i++)
{
crc = crc ^ ((unsigned int)buf<<8);
for(j = 0;
j < 8;
++j)
{
if(crc &
0x8000)
crc = (crc << 1)^0x1021;
else
crc = crc << 1;
}
}
return crc;
}
Pascal:
function TForm1.Check_CRC(buf:TBytes;len:integer):word;//TBytes是個數組
var
i,j: integer;
crc:word;
begin
crc:=0;
for i:=0 to len-1do
begin
crc:=crc xor (word(buf) shl 8);
for j:=0 to 7do
begin
if (crc and $8000)=$8000 then
crc:=((crc shl 1) xor $1021)
else
crc:=crc shl 1;
end;
end;
result:=crc;
end;
crc_data(char *buf, int len)
{
int i, j;
unsigned int crc = 0;
for(i = 0;
i < len;
i++)
{
crc = crc ^ ((unsigned int)buf<<8);
for(j = 0;
j < 8;
++j)
{
if(crc &
0x8000)
crc = (crc << 1)^0x1021;
else
crc = crc << 1;
}
}
return crc;
}
Pascal:
function TForm1.Check_CRC(buf:TBytes;len:integer):word;//TBytes是個數組
var
i,j: integer;
crc:word;
begin
crc:=0;
for i:=0 to len-1do
begin
crc:=crc xor (word(buf) shl 8);
for j:=0 to 7do
begin
if (crc and $8000)=$8000 then
crc:=((crc shl 1) xor $1021)
else
crc:=crc shl 1;
end;
end;
result:=crc;
end;