zoukankan      html  css  js  c++  java
  • (65)CRC32校验C语言版本

    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 ", crc32(0, s, strlen(s)));
    28. system("pause");
    29. return 0 ;
    30. }
  • 相关阅读:
    怎样用HTML5 Canvas制作一个简单的游戏
    js面向对象
    javascript闭包
    javascript变量的作用域
    5-22
    5-23
    14-5-21 硬代码
    14-5-19 类和对象
    array
    生成干扰线
  • 原文地址:https://www.cnblogs.com/wycBlog/p/7659716.html
Copyright © 2011-2022 走看看