[comp.lang.c] CRC-16 source code wanted

paul@frcs.UUCP (Paul Nash) (04/18/91)

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.

Many thanks

 ---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---=---
Paul Nash				   Free Range Computer Systems cc
paul@frcs.UUCP				      ...!uunet!m2xenix!frcs!paul

oz@yunexus.yorku.ca (Ozan Yigit) (04/24/91)

In article <461@frcs.UUCP> paul@frcs.UUCP (Paul Nash) writes:

>I am looking for C source code to implement the CRC-16 algorithm.

I sent you something that may be of some use. In case you need
some literature refs for future use, here is something that is
easy to implement:

%A Georgia Griffiths
%A G. Carlyle Stones
%T The Tea-Leaf Reader Algorithm:
An Efficient Implementation of CRC-16 and CRC-32
%J Communications of the ACM
%V 30
%N 7
%D 1987
%P 617-620

hope this is useful.	oz
---
SunOS: There are many edible ways to serve | internet: oz@nexus.yorku.ca
up scrambled eggs, but one cannot get them | uucp: utzoo/utai!yunexus!oz
back as over-easy or sunny side up.  -- oz | phone: [416] 736 5257x33976

gwyn@smoke.brl.mil (Doug Gwyn) (04/24/91)

In article <461@frcs.UUCP> paul@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.

In the past few days, R.Hyde and I have been using CRC-16 as an example
for comparison of programming in C vs. assembler, in the comp.sys.apple2
newsgroup.  If it hasn't yet expired on your site, grep the archives for
"crc".

vg@sjoki.uta.fi (Vesa Gynther) (04/24/91)

I remember seeing a code fragment in SEA ARC v. 5.12 source code, which was
used to calculate 16 bit CRC's.  The hard part is - I don't remember where
I found that source code.  Probably you'll find it in some well equipped
anon ftp site (simtel20 ?) =-)

ake@dayton.saic.com (Earle Ake) (04/24/91)

In article <461@frcs.UUCP>, paul@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@dayton.saic.com        uucp: dayvb!ake         SPAN: 28284::ake

Demoel@Fwva.Saic.Com (Ed de Moel) (04/24/91)

vg@sjoki.uta.fi (Vesa Gynther) writes:
>I remember seeing a code fragment in SEA ARC v. 5.12 source code, which was
>used to calculate 16 bit CRC's.  The hard part is - I don't remember where
>I found that source code.  Probably you'll find it in some well equipped
>anon ftp site (simtel20 ?) =-)
 
I've seen the code posted on this mailgroup. What I am looking for
is a reference to the standard that defines it.
I know the algorithm and have code that executes it.
Anyone out there who knows the name of the standard? As far as
my knowledge goes, it must be a CCITT standard, but what is the
number?
 
Thanks in advance,
Ed