校验法

liujiuhua 2007-12-24 11:43:14
unsigned int CalCrc(char * buffer,unsigned int count)
{
unsigned int i,j;
unsigned int CrcValue = 0;
for(i=0;i<count;i++)
{

CrcValue = CrcValue ^ ( buffer[i] << 8 );

for (j = 0; j < 8; j++)
if (CrcValue & 0x8000)
CrcValue = (CrcValue << 1) ^ 0x1021;
else
CrcValue = CrcValue << 1;
}
return (CrcValue);
}
请问以上代码用delphi怎么写
...全文
32 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanguomi 2007-12-24
楼上的应该没问题
回复
edongxu 2007-12-24

Function GetCRC(Buf:pchar;len:integer):DWord;
var
i,j:integer;
temp:integer;
begin
Result := $0;
//---------------------------------------------------------
For i := 0 to len-1 do
begin
Result := Result xor (ord(Buf[i]) shl 8) ;
//-------------------------------------------------------
For j :=1 to 8 do
begin
temp := Result and $8000;
Result := Result shl 1;
if temp = 1 then Result := Result xor $1021;
end;
//-------------------------------------------------------
end;
//--------------------------------------------------------

end;


回复
hongqi162 2007-12-24
http://www.sxlist.com/techref/method/crc_delphi.htm
回复
CYDong0423 2007-12-24
^_^关注学习^_^
回复
liujiuhua 2007-12-24
大家顶呀
回复
发动态
发帖子
网络通信/分布式开发
创建于2007-08-02

1565

社区成员

Delphi 网络通信/分布式开发
申请成为版主
社区公告
暂无公告