Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/06/01 09:20
Read: times


 
#16298 - CRC16 - Can someone check my results
Hi

I have a CRC16 function I downloaded from somewhere (all credit to whoever wrote it)

however I have no Other CRC generation program to check it against (the chicken and Egg scenario, If I wirte another one, how do I know which is right)

so I am using a CRC16 with a poly of 0x01800500 the test string is "Marshall" with the resulting CRC = 0x9E32

the function is below (comments on whether it is any good are also welcome)

unsigned short CalculateCRC( unsigned char *buf, byte num );

/**************** CalculateCRC ************************/

unsigned short CalculateCRC( unsigned char *buf, byte num )
{
byte i,j;
unsigned long sum;
unsigned short crc;
unsigned long polynomial = 0x01800500; //CRC-16
//0x01102100; //CCITT-16

sum = 0;
for( i=0; i< num; i++)
{
sum |= *(buf+i);
for( j=0; j< 8; j++)
{
sum <<= 1;
if( sum & 0x01000000 )
sum ^= polynomial;
}
}
for( i=0; i< 2; i++) // last 2 byte zero
{
sum |= 0x00;
for( j=0; j< 8; j++)
{
sum <<= 1;
if( sum & 0x01000000 )
sum ^= polynomial;
}
}

crc = ( sum>>8 ) & 0x0000FFFF;
return( crc );
}



Thanks and Regards

Marshall

List of 14 messages in thread
TopicAuthorDate
CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: Peter\'s link for the idle amongst us            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone duh            01/01/70 00:00      
RE: CRC16 - Can someone check my results            01/01/70 00:00      
RE: CRC16 - Can someone duh            01/01/70 00:00      

Back to Subject List