封装一个函数;计算CRC校验。 谢谢各位啊(80分)

D

dm09

Unregistered / Unconfirmed
GUEST, unregistred user!
计算CRC校验。校验多项式107H,数据段为6字节构成的48位码流,用校验多项式作为除数除以码流,相除异或;最后得到8位余数取反后就是校验码,谢谢各位,小弟 没弄过CRC校验
 
你说的这些就是你校验的方法,你按这个方法写个过程计算一下就是所谓的校验了
 
谢谢 怎么封装啊 我不太清楚
 
你说的是 crc8 ,你网上看看有相类似的,
主要要看看多项式是不是相同的.
 
在pchar后面加上两位的crc
Function CheckCRC(MSB:pchar):Boolean;
var
i,MSBlen:Integer;
tmp:Byte;
A,B:char;
begin
MSBlen:=StrLen(MSB);
tmp:=ord(MSB[0]);
for i:=1 to MSBlen-4do
begin
tmp:=tmp xor ord(MSB);
end;

A:= chr(tmp and $F0);
B:= chr(tmp and $0F);
if (A<>MSB[MSBlen-3]) or (B<>MSB[MSBlen-2]) then
Result:=False
else
Result:=True;

end;

procedure MakeCRC(MSB:pchar);
var
i,MSBlen:Integer;
tmp:byte;
begin
MSBlen:=StrLen(MSB);
tmp:=ord(MSB[1]);
for i:=2 to MSBlen-1do
begin
tmp:=(tmp xor ord(MSB));
end;

if ((tmp and $F0) shr 4) >=10 then
MSB[MSBlen]:=chr(((tmp and $F0) shr 4)+55)
else
MSB[MSBlen]:=chr(((tmp and $F0) shr 4)+48);
if (tmp and $0F)>=10 then
MSB[MSBlen+1]:=chr((tmp and $0F)+55)
else
MSB[MSBlen+1]:=chr((tmp and $0F)+48);

MSB[MSBlen+2]:= ETX;
MSB[MSBlen+3]:= #0;

end
 
我没太看明白楼上哥哥的东西,因为我对CRC一点都不熟悉
 

Similar threads

S
回复
0
查看
955
SUNSTONE的Delphi笔记
S
S
回复
0
查看
776
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
869
DelphiTeacher的专栏
D
顶部