Come è possibile tradure il seguente codice C in un più compresibile VB6 o VB.net:
/************************************************** **************
CRC16 16bit CRC
CCITT CRC16
Cyclical Redundancy Check
polynomial: X^16 + X^12 + X^5 + 1
(used in XMODEMCRC communications protocol)
************************************************** ***************/
union _crc {
unsigned char b[2]; /* high byte is b[1], low byte is b[0] */
unsigned w; /* word value */
};
unsigned crc16(len, start_crc, p)
int len; /* length of p */
unsigned start_crc; /* starting value, initialize to zero */
unsigned char *p; /* pointer to memory of which to calculate crc */
{
union _crc crc;
int i;
crc.w = start_crc; /* set up starting value of CRC */
while (len-- >0)
{
crc.b[1] ^= *p++; /* xor value of next byte into HIGH byte of CRC */
/* this is for an 80x86 processor */
for(i=0;i<8;++i)
if (crc.w & 0x8000) /* high bit set?? */
{
crc.w <<= 1; /* left shift one */
crc.w ^= 0x01021; /* XOR value 0x1021 */
}
else
{
crc.w <<= 1; /* left shift one */
}
}
return (crc.w);
}
char hello[] = “Hello World!”;
unsigned crc;
crc = crc16(strlen(hello), 0, hello);
printf(“%04x\n”,crc);