CRC-16 source code wanted

Earle Ake ake at dayton.saic.com
Wed Apr 24 23:40:46 AEST 1991


In article <461 at frcs.UUCP>, paul at frcs.UUCP (Paul Nash) writes:
> 
> I am looking for C source code to implement the CRC-16 algorithm.  I
> have seen various from time to time, but cannot think of a place.  If
> you have a suitable (short) routine, please post it or mail me a copy,
> or tell me where I can find one.

int calcrc(prt, count)
char *ptr;
int count;
{
	int crc, i;

	crc = 0;
	while (--count >= 0) {
		crc = crc ^ (int)*ptr++ << 8;
		for (i = 0; i < 8; ++i)
			if (crc & 0x8000)
				crc = crc << 1 ^ 0x1021;
			else
				crc = crc << 1;
		}
	return (crc & 0xFFFF);
}


Earle
_____________________________________________________________________________
             ____ ____    ___
Earle Ake   /___ /___/ / /     Science Applications International Corporation
           ____//   / / /__                 Dayton, Ohio
-----------------------------------------------------------------------------
Internet: ake at dayton.saic.com        uucp: dayvb!ake         SPAN: 28284::ake



More information about the Comp.lang.c mailing list