工业物联网集成了微电子计算技术、通信技术、云平台、大数据技术以及工业生产运营技术,是未来物联网运用最重要的方向。
作者:KingKa Wu 欢迎任何形式的转载,但请务必注明出处。 限于本人水平,如果文章和代码有表述不当之处,还请不吝赐教。
  1. #include<iostream>
  2. # include <stdio.h>
  3. # include <string.h>
  4. typedef unsigned int uint ;
  5. uint POLYNOMIAL = 0xEDB88320 ;
  6. int have_table = 0 ;
  7. uint table[256] ;
  8. void make_table()
  9. {
  10. int i, j, crc ;
  11. have_table = 1 ;
  12. for (i = 0 ; i < 256 ; i++)
  13. for (j = 0, table[i] = i ; j < 8 ; j++)
  14. table[i] = (table[i]>>1)^((table[i]&1)?POLYNOMIAL:0) ;
  15. }
  16. uint crc32(uint crc, char *buff, int len)
  17. {
  18. if (!have_table) make_table() ;
  19. crc = ~crc;
  20. for (int i = 0; i < len; i++)
  21. crc = (crc >> 8) ^ table[(crc ^ buff[i]) & 0xff];
  22. return ~crc;
  23. }
  24. int main ()
  25. {
  26. char s[] = "676547657567";
  27. printf("%08Xh\n", crc32(0, s, strlen(s)));
  28. system("pause");
  29. return 0 ;
  30. }
posted on 2017-10-13 10:04  KingKa_Wu  阅读(620)  评论(1编辑  收藏  举报