|
|
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) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.algorithms/16795a71f5dab.html, оценка из 5, голосов 10
|