[APM32F4] 分享一个大佬写的一个CRC32table表生成源代码

[复制链接]
12|0
ShadowDance 发表于 2025-10-29 01:27 | 显示全部楼层 |阅读模式
  1. #include <stdio.h>
  2. #include <stdint.h>

  3. #if 0
  4. #define POLY        0x04c11db7
  5. #define POSTFIX      "04c11db7"
  6. #define POLY        0x1EDC6F41
  7. #define POSTFIX      "1edc6f41"
  8. #define POLY        0xA833982B
  9. #define POSTFIX      "a833982b"
  10. #define POLY        0x000000AF
  11. #define POSTFIX      "000000af"
  12. #endif

  13. #define POLY        0x814141AB
  14. #define POSTFIX      "814141ab"

  15. int main (void)
  16. {
  17.     uint32_t i, j;
  18.     uint32_t c;
  19.     uint32_t table[256];

  20.     for (i = 0; i < 256; i++) {
  21.         for (c = i << 24, j = 8; j > 0; --j)
  22.             c = c & 0x80000000 ? (c << 1) ^ POLY : (c << 1);
  23.         table[i] = c;
  24.     }

  25.     printf ("static const uint32_t crc32_table_" POSTFIX "[] =\n{\n");
  26.     for (i = 0; i < 256; i += 4)
  27.     {
  28.         printf ("  0x%08x, 0x%08x, 0x%08x, 0x%08x",
  29.                 table[i + 0], table[i + 1], table[i + 2], table[i + 3]);
  30.         if (i + 4 < 256)
  31.             putchar (',');
  32.         putchar ('\n');
  33.     }
  34.     printf ("};\n");
  35.     return 0;
  36. }
这段代码可以输出CRC32的查找表。原作者可是大佬!


您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

34

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部