Главная страница


ru.algorithms

 
 - RU.ALGORITHMS ----------------------------------------------------------------
 From : Dmitry Guyvoronsky                   2:5020/400     10 Dec 2001  11:54:45
 To : Sasha Ivanov
 Subject : Re: crc32
 -------------------------------------------------------------------------------- 
 
 > Люди подскажите как сабж посчитать.
 
 ...
 
 The following C code (by Rob Warnock <rpw3@sgi.com>) does CRC-32 in
 BigEndian/BigEndian byte/bit order.  That is, the data is sent most
 significant byte first, and each of the bits within a byte is sent most
 significant bit first, as in FDDI. You will need to twiddle with it to do
 Ethernet CRC, i.e., BigEndian/LittleEndian byte/bit order. [Left as an
 exercise for the reader.] The CRCs this code generates agree with the
 vendor-supplied Verilog models
 of several of the popular FDDI "MAC" chips. u_long crc32_table[256];
 /* Initialized first time "crc32()" is called. If you prefer, you can
  * statically initialize it at compile time. [Another exercise.]
  */ u_long crc32(u_char *buf, int len)
 {
         u_char *p;
         u_long  crc;         if (!crc32_table[1])    /* if not already done,
 */
                 init_crc32();   /* build table */
         crc = 0xffffffff;       /* preload shift register, per CRC-32 spec
 */
         for (p = buf; len > 0; ++p, --len)
                 crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
         return ~crc;            /* transmit complement, per CRC-32 spec */
 } /*
  * Build auxiliary table for parallel byte-at-a-time CRC-32.
  */
 #define CRC32_POLY 0x04c11db7     /* AUTODIN II, Ethernet, & FDDI */
 init_crc32()
 {
         int i, j;
         u_long c;         for (i = 0; i < 256; ++i) {
                 for (c = i << 24, j = 8; j > 0; --j)
                         c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c <<
 1);
                 crc32_table[i] = c;
         }
 }
 --
 WBR Dmitry
 --- ifmail v.2.15dev5
  * Origin: Svit Online (post does not reflect views of Golden Tele (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 crc32   Sasha Ivanov   09 Dec 2001 23:54:58 
 Re: crc32   Dmitry Guyvoronsky   10 Dec 2001 11:54:45 
 crc32   Andrey Orlenko   12 Dec 2001 02:56:05 
 crc32   Eugene Zagidullin   13 Dec 2001 01:13:19 
 crc32   Max Alekseyev   12 Dec 2001 18:53:44 
 crc32   Andrey Orlenko   13 Dec 2001 06:24:00 
 crc32   Stepan Polovnikov   13 Dec 2001 20:09:52 
 crc32   Eugene Zagidullin   14 Dec 2001 00:41:05 
 crc32   Stepan Polovnikov   14 Dec 2001 20:58:25 
 crc32   George Shepelev   13 Dec 2001 21:38:13 
 crc32   Eugene Zagidullin   15 Dec 2001 00:33:42 
 crc32   Dennis Chikin   20 Mar 2002 22:57:51 
 crc32   Max Alekseyev   22 Mar 2002 12:41:32 
Архивное /ru.algorithms/16795a71f5dab.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional