標(biāo)題: CRC32非查表范例,驗(yàn)證可用 [打印本頁]

作者: again00txhj    時(shí)間: 2021-6-18 17:29
標(biāo)題: CRC32非查表范例,驗(yàn)證可用

  1. //Polynomial representations
  2. //
  3. //Normal :0x04C11DB7
  4. //Reversed :0xEDB88320
  5. //Reversed reciprocal :0x82608EDB

  6. unsigned long CRC_32;

  7. unsigned  long crc32_in_c(unsigned  char *p, unsigned  char len)
  8. {
  9.         unsigned  char        i,j;
  10.             unsigned  long crc = 0xffffffff;
  11.             for(j=0;j<len;j++)
  12.             {
  13.                 crc = crc ^ *p++;
  14.                 for (i = 0;i<8;i++)
  15.                 {
  16.                     crc = (crc >> 1) ^ (0xedb88320 &  -(crc & 1));
  17.                 }
  18.             }
  19.             return ~crc;
  20. }
  21. //================================================
  22. void        main()
  23. {

  24.                 p_data[0]=0x33;
  25.                 p_data[1]=0x34;
  26.                 p_data[2]=0x35;
  27.                 CRC_32= crc32_in_c((unsigned  char *)&p_data[0], 3);
  28. }
復(fù)制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1