home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!wupost!csus.edu!netcom.com!pdh
- From: pdh@netcom.com (Phil Howard )
- Subject: Re: CRC-32 C code needed
- Message-ID: <1992Nov19.203907.24656@netcom.com>
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <17583@mindlink.bc.ca>
- Date: Thu, 19 Nov 1992 20:39:07 GMT
- Lines: 46
-
- a7657@mindlink.bc.ca (Stephen H. Kawamoto) writes:
-
- > for ( c = i << 24, j = 8; j > 0; --j)
- > ========
- > this loses bits
-
- If you need to keep more than 8 bits, then you need to do something else.
- If 8 bits is all you need to keep (in c) then you need to declare "i" as
- an (unsigned long) which will have a minimum the needed room to shift.
- Of course "c" will have to be that big just to hold those 8 bits on the
- high order end. Or you can cast it (parenthesis are just a practice to
- make SURE things are evaluated in the desired order, using the rule that
- says multiply and divide are done before add and subtract and put EVERYthing
- else in parenthesis):
-
- c = ( (unsigned long) i ) << 24;
- for ( j = 8; j > 0; --j)
-
-
- > and when the table is built,
- >
- > crc = (crc << 8 ) ^ crc_table[(crc >> 24) ^ *p];
- > =========
- > this loses significent
- > bits
-
- Again, "crc" itself needs to be a 32 bit number AND you are only going to be
- keeping the high order 8 bits.
-
- And be sure EVERYTHING with bits in it is declared as UNSIGNED.
-
-
-
- > is there a better way to do this?
- >
- >Stephen Kawamoto <a7657@mindlink.bc.ca>
-
- Maybe. You didn't show enough code to make judgements. I'll send you
- a copy of my code by e-mail (tarred, compressed, and uuencoded) which
- you can study, compare, extract or use (even though it is still just in
- beta test).
- --
- /***********************************************************************\
- | Phil Howard --- KA9WGN --- pdh@netcom.com | "The problem with |
- | depending on government is that you cannot depend on it" - Tony Brown |
- \***********************************************************************/
-