一个串口设备需要CRC校验,厂家给的代码不是delphi,我不会,哪个高手帮我写成delphi的(100)

  • 主题发起人 feng7504
  • 开始时间
F

feng7504

Unregistered / Unconfirmed
GUEST, unregistred user!
Unsigned int. crc;Unsigned int. x, i;I=0;crc=0;while (i<=包长){x=int (buff1[i]);x=x<<8;crc^=x;for (x=0; x<8; x++){ if (crc & 0x8000){ crc= (crc<<1); crc^=0x1021; } else crc= (crc<<1);}crc &=0xffff;i++;}其中buff[I]代表包长部分各个字节;
 
http://delphibbs.com/delphibbs/dispq.asp?lid=3988650可以参考上面的链接procedure TForm1.FormCreate(Sender: TObject);var x,i,crc,packedlen:Integer; buff1:array of Byte;beginSetLength(buff1,packedlen);i:=0;crc:=0;while i<=packedlen-1 dobegin x:= buff1; crc:=crc xor x; for x:=0 to 8-1 do begin if (crc and $8000)<>0 then begin crc:=crc shl 1; crc:=crc xor $1021; end else begin crc:=crc shl 1; end; end; Inc(i);end;end;
 
接受答案了.
 

Similar threads

I
回复
0
查看
544
import
I
I
回复
0
查看
733
import
I
I
回复
0
查看
710
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部