厂家提供的 代码如下
i:=$ffff; //1 CRC-16
for k:=0 to count-1 do
begin
ih:=i div 256; //2 data[k]:引导字节开始的数据
il:=i mod 256;
il:=il xor data[k];
i:=ih*256+il;
for j:=0 to 7 do
begin
l:=i;
i:=i div 2; //3
if (l mod 2)<>0 then //4
begin
i:=i xor $a001;
end;
end; //5
end; //6
i:=i mod 65536;
c[0]:=i mod 256;
c[1]:=i div 256;
//
用pb如何写
俺没做过
不难理解呀,你只要懂得十六进制与二进制的转换就行了,把“FFFF”当作65536,然后进行一些异或运算,只是PB里没有异或运算,要自己写
同意pbsql(风云)的说法!
i:=65535 //1 CRC-16
for k=0 to count-1
i=cxor(i,data[k])
for j=0 to 7
l:=i;
i=i/2; //3
if (mod(l,2)<>0 then //4
i=cxor(i,40961)
end if
next
next
i=i/65536
c[0]=i/256
c[1]=mod(i,256)
这是我给你改写的pb代码,异或的函数定义和dll你可以给我发消息留
下你的mail我寄给你
我习惯把十六进制数据转成string,然后处理,我这有一个xor函数,权且抛砖引玉:
$PBExportHeader$gf_bitsxor.srf
global type gf_bitsxor from function_object
end type
forward prototypes
global function string gf_bitsxor (string as_source1, string as_source2)
end prototypes
global function string gf_bitsxor (string as_source1, string as_source2);long ll_pos
string ls_char1,ls_char2
string ls_ret
setnull(ls_ret)
if isnull(as_source1) or isnull(as_source2) or as_source1 = or as_source2 = or len(as_source1) <> len(as_source2) then
return ls_ret
end if
ls_ret =
for ll_pos = 1 to len(as_source1)
ls_char1 = mid(as_source1,ll_pos,1)
ls_char2 = mid(as_source2,ll_pos,1)
if (ls_char1 <>0and ls_char1<> 1) or (ls_char2 <>0and ls_char2<> 1) then
return ERROR
end if
if ls_char1 = ls_char2 then
ls_ret = ls_ret + 1
else
ls_ret = ls_ret + 0
end if
end for
return ls_ret
end function