I need assistance with converting this CRC function from C to Delphi. My knowledge of C is rather limited. Thanks
I need assistance with converting this CRC function from C to Delphi. My knowledge of C is rather limited. Thanks
word CRC_16(byte *buf,word len)
{
word crc=0x0000;
byte c,i;
while (len!=0)
{
c=*buf;
for (i=0;i<8;i++)
{
if ((crc ^ c) & 1)
crc=(crc>>1)^0xa001;
else
crc>>=1;
c>>=1;
}
len--;
buf++;
}
return (crc);
}
word CRC_16(byte *buf,word len)
{
word crc=0x0000;
byte c,i;
while (len!=0)
{
c=*buf;
for (i=0;i<8;i++)
{
if ((crc ^ c) & 1)
crc=(crc>>1)^0xa001;
else
crc>>=1;
c>>=1;
}
len--;
buf++;
}
return (crc);
}
Achim Kalwa Great thanks
ReplyDeleteWith code translations or replacement for translations, always ensure you have test cases for the untranslated code and the replacement/translation.
ReplyDeleteAchim Kalwa good job! Hopefully, your conversion will help more than one person cross the bridge to a new language. That's how I got started with "C".
ReplyDelete