home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16822 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.3 KB  |  57 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!wupost!csus.edu!netcom.com!pdh
  3. From: pdh@netcom.com (Phil Howard )
  4. Subject: Re: CRC-32 C code needed
  5. Message-ID: <1992Nov19.203907.24656@netcom.com>
  6. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  7. References: <17583@mindlink.bc.ca>
  8. Date: Thu, 19 Nov 1992 20:39:07 GMT
  9. Lines: 46
  10.  
  11. a7657@mindlink.bc.ca (Stephen H. Kawamoto) writes:
  12.  
  13. >                  for ( c = i << 24, j = 8; j > 0; --j)
  14. >                            ========
  15. >                             this loses bits
  16.  
  17. If you need to keep more than 8 bits, then you need to do something else.
  18. If 8 bits is all you need to keep (in c) then you need to declare "i" as
  19. an (unsigned long) which will have a minimum the needed room to shift.
  20. Of course "c" will have to be that big just to hold those 8 bits on the
  21. high order end.  Or you can cast it (parenthesis are just a practice to
  22. make SURE things are evaluated in the desired order, using the rule that
  23. says multiply and divide are done before add and subtract and put EVERYthing
  24. else in parenthesis):
  25.  
  26.         c = ( (unsigned long) i ) << 24;
  27.         for ( j = 8; j > 0; --j)
  28.  
  29.  
  30. >        and when the table is built,
  31. >
  32. >                        crc = (crc << 8 ) ^ crc_table[(crc >> 24) ^ *p];
  33. >                                                       =========
  34. >                                                       this loses significent
  35. >                                                       bits
  36.  
  37. Again, "crc" itself needs to be a 32 bit number AND you are only going to be
  38. keeping the high order 8 bits.
  39.  
  40. And be sure EVERYTHING with bits in it is declared as UNSIGNED.
  41.  
  42.  
  43.  
  44. >                       is there a better way to do this?
  45. >
  46. >Stephen Kawamoto <a7657@mindlink.bc.ca>
  47.  
  48. Maybe.  You didn't show enough code to make judgements.  I'll send you
  49. a copy of my code by e-mail (tarred, compressed, and uuencoded) which
  50. you can study, compare, extract or use (even though it is still just in
  51. beta test).
  52. -- 
  53. /***********************************************************************\
  54. | Phil Howard  ---  KA9WGN  ---  pdh@netcom.com   |   "The problem with |
  55. | depending on government is that you cannot depend on it" - Tony Brown |
  56. \***********************************************************************/
  57.