Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ryesone.UUCP Path: utzoo!utcs!ryesone!mason From: mason@ryesone.UUCP (Dave Mason) Newsgroups: net.dcom,net.lan Subject: Problem with CRC calculation...need help Message-ID: <130@ryesone.UUCP> Date: Wed, 2-Apr-86 18:46:20 EST Article-I.D.: ryesone.130 Posted: Wed Apr 2 18:46:20 1986 Date-Received: Wed, 2-Apr-86 19:42:55 EST Distribution: net Organization: Ryerson School of Computer Science, Toronto, ON Lines: 61 Xref: utcs net.dcom:1771 net.lan:1375 I thought I had a working CRC routine, but it doesn't seem to net to a zero. For background a CRC-CCITT or CRC-16 calculated on a message (plus 2 zero bytes) gives 2 CRC characters. If you calculate the CRC on the message with the CRC characters replacing the zero bytes should give zeros for the CRC. My CRC routine gives a number that is zero mod 256, but not necessarily 0. Any help would be appreciated. The code follows: int crc; main() { check("asdfks"); check("abc"); check("1231455"); } check(omsg) char *omsg; { int i,j; int ch; char *msg; printf(">>>>>>>>\n"); msg=omsg; crc=0; while (ch = *msg++) docrc(ch); docrc(0); docrc(0); i=crc/256 % 256; j=crc %256; printf("------\n"); msg=omsg; crc=0; while (ch = *msg++) docrc(ch); docrc(i); docrc(j); printf("crc=%d\n",crc); } docrc(ch) int ch; { register int n; register int i,t; n=ch; n &= 255; printf("ch=%d ",n); i=8; t=crc; while (--i>=0) { n<<=1; t<<=1; if (n & 256) ++t; if (crc<0) t ^= 0x1021; crc=t; } printf("crc=%d\n",crc); } Thanks... -- usenet: ..!utzoo!utcsri!mason Dave Mason, U. Toronto CSRI ..!utzoo!ryesone!mason Dave Mason, Ryerson Polytechnical Institute CSNET: mason@Toronto ARPA: mason%Toronto@CSNet-Relay BITNET: FCTY7053@RYERSON.BITNET