找程序的错,c程序改为delphi(50分)

  • 主题发起人 主题发起人 lvzhijong
  • 开始时间 开始时间
L

lvzhijong

Unregistered / Unconfirmed
GUEST, unregistred user!
那位帮忙找程序的错,我转化后两边运行结果不一样
是将以下c程序转为delphi的函数
我转化后两边运行结果不一样
包括3个函数:iCal_crc、CalcTable、UpdateCRC,后2个由第1个调用,
只需调用iCal_crc
#define POLY 0x1021
unsigned int iCal_crc(int *ipP,int iPack_long);
unsigned int CalcTable(unsigned int dat,unsigned int genpoly,unsigned int accum);
unsigned int UpdateCRC(unsigned int crc,unsigned int wdata);
unsigned int iCal_crc(int *ipP,int iPack_long)
{
unsigned int j,iChecksum;
iChecksum = 0;
for(j=0;j<iPack_long;j++)
{
iChecksum=UpdateCRC(iChecksum,*ipP++);
}
return(iChecksum);
}
unsigned int CalcTable(unsigned int dat,unsigned int genpoly,unsigned int accum)
{
int i;
dat <<= 8;
for(i=8;i>0;i--)
{
if((dat^accum) &amp;
0x8000) accum = (accum << 1) ^ genpoly;
else
accum <<= 1;
dat <<= 1;
}
return(accum);
}
unsigned int UpdateCRC(unsigned int crc,unsigned int wdata)
{
return((crc<<8)^CalcTable((crc>>8)^wdata,POLY,0));
}
function calctable(dat,genpoly,accum:word):word;
// unsigned int CalcTable(unsigned int dat,unsigned int genpoly,unsigned int accum)
var
i:byte;
//int i;
begin
dat:=dat shl 8;
//dat <<= 8;
for i:=7do
wnto 1do
// for(i=8;i>0;i--)
begin
if (word(dat or accum) and $8000)<>0 then
accum:=word(accum shl 1) or genpoly
// if((dat^accum) &amp;
0x8000) accum = (accum << 1) ^ genpoly;
else
accum:=accum shl 1;
//else
accum <<= 1;
showmessage(inttostr(accum));
dat:=dat shl 1;
//dat <<= 1;
end;
result:=accum;
// return(accum);
test2:=result;
showmessage('test2 '+inttostr(test2));
end;

function updateCRC(crc,wdata:word):word;
// unsigned int UpdateCRC(unsigned int crc,unsigned int wdata)
begin
result:=(crc shl 8) or calctable((crc shr 8) or wdata,poly,0);
test1:=result;
showmessage('test1 '+inttostr(test1));
// return((crc<<8)^CalcTable((crc>>8)^wdata,POLY,0));
end;

function iCal_crc(ipP:pointer;iPack_long:word):word;
//unsigned int iCal_crc(int *ipP,int iPack_long)
var
s:array[1..249] of byte;
j,ichecksum:word;
//unsigned int j,iChecksum;
begin
move(ipP^,s,iPack_long);
// showmessage(inttostr(s[3]));
ichecksum:=0;
//iChecksum = 0;
for j:=1 to ipack_longdo
//for(j=0;j<iPack_long;j++)
ichecksum:=updatecrc(ichecksum,s[j]);
//iChecksum=UpdateCRC(iChecksum,*ipP++);
result:=ichecksum;
// return(iChecksum);
end;
 
for i:=8do
wnto 1 ?
请贴全
 
to Kang:
已经解决了,不过还是要感谢你
给你15分,替我保密行吗?
因为我是个菜鸟,有好多问题要问。
 
多人接受答案了。
 
后退
顶部