请高手把下面一段转换成Delphi语言,在线等待....

shengtian 2003-10-16 08:21:33
/*
* Calculate a new fcs given the current fcs and the new data.
*/
__u16 pppfcs16(fcs, cp, len)
register __u16 fcs;
register unsigned char *cp;
register int len;
{
while (len--)
fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
return (fcs);
}

/*
* generate CRC16
*/
__u16 gen_fcs16(unsigned char *cp, int len)
{
__u16 fcs;

/* add on output */
fcs = pppfcs16(PPP_INITFCS, cp, len);
fcs ^= 0xffff; /* complement */

return fcs;
/*
cp[len] = (fcs & 0x00ff); // least significant byte first
cp[len+1] = ((fcs >> 8) & 0x00ff);
*/
}

/*
* check received data block
*/
__u16 chk_fcs16(unsigned char *cp, int len)
{
__u16 fcs;

fcs = pppfcs16(PPP_INITFCS, cp, len);
return fcs;

/*
if (fcs == PPP_GOODFCS)
return SUCCESS;
*/
}
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigerhohoo 2003-10-16
  • 打赏
  • 举报
回复
function pppfcs16( fcs : Word;
cp : PByte;
len : integer ) : Word ;
begin
pppfcs16 := fcs;
while (len > 0) do
begin
fcs := fcs shr 8;
fcs := fcs xor fcstab[(fcs xor cp^) and $ff];
Inc(cp, 1);
Dec(len);
end;
pppfcs16 := fcs;
end;

function gen_fcs16(cp : PByte; len : integer) : Word;
var
fcs : Word;

begin
fcs := pppfcs16(PPP_INITFCS, cp, len);
fcs := fcs xor $ffff;
Result := fcs;
end;

function chk_fcs16(cp : PByte; len : integer) : Word;
var
fcs : Word;
begin
fcs := pppfcs16(PPP_INITFCS, cp, len);
Result := fcs;
end;
shengtian 2003-10-16
  • 打赏
  • 举报
回复
就这些了,哦,还有个数组,不过,只要翻译的正确就可以,相信在我这里会通过的。
shengtian 2003-10-16
  • 打赏
  • 举报
回复
我知道简单,可我不会呀,主要是指针运算后才自身加1,在delphi中不知道如何处理,希望能把整个的程序转义过来,不要片断,否则还是不行。谢谢。
aiirii 2003-10-16
  • 打赏
  • 举报
回复
很簡單就可翻譯, 但你給的資料不全, 現在的代碼修改後無法中 delphi 中編繹過!!

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧