把C/C++转换成Delphi
unsignedcharCrcCalc(unsignedcharc,unsignedcharoldCrc){//CRC-8Cx=X8+X2+X+1unsignedchar...
unsigned char CrcCalc(unsigned char c,unsigned char oldCrc)
{
//CRC-8 Cx=X8+X2+X+1
unsigned char i;
oldCrc = oldCrc ^ c;
for(i = 0; i < 8; i++)
{
if(0x80 & oldCrc)
{
oldCrc = oldCrc << 1;
oldCrc = oldCrc ^ 7; //7 is the polynomail
}
else
{
oldCrc = oldCrc << 1;
}
}
return oldCrc;
} 展开
{
//CRC-8 Cx=X8+X2+X+1
unsigned char i;
oldCrc = oldCrc ^ c;
for(i = 0; i < 8; i++)
{
if(0x80 & oldCrc)
{
oldCrc = oldCrc << 1;
oldCrc = oldCrc ^ 7; //7 is the polynomail
}
else
{
oldCrc = oldCrc << 1;
}
}
return oldCrc;
} 展开
展开全部
function TForm1.CrcCalc(c, oldCrc: Byte): Byte;
var
i: Byte;
begin
oldCrc:= oldCrc xor c;
for I := 0 to 7 do
begin
if ($80 and oldCrc)<>0 then
begin
oldCrc:=oldCrc shl 1;
oldCrc:=oldCrc xor 7;
end
else
oldCrc:=oldCrc shl 1;
end;
Result:=oldCrc;
end;
var
i: Byte;
begin
oldCrc:= oldCrc xor c;
for I := 0 to 7 do
begin
if ($80 and oldCrc)<>0 then
begin
oldCrc:=oldCrc shl 1;
oldCrc:=oldCrc xor 7;
end
else
oldCrc:=oldCrc shl 1;
end;
Result:=oldCrc;
end;
追问
接收串口数据
SetLength(Str,BufferLength);
move(buffer^,pchar(@Str[1])^,bufferlength);
memo1.Text:=memo1.Text+' '+StrToHexStr(Str)+']'+' ';
对接收来的数据进行 校验和 的对比判断该怎么写啊!麻烦这位大大啦!!
追答
加我qq吧,2533+7012
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询