⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc.c

📁 CRC16的源程序
💻 C
字号:
   /* (Extracted from a document edited by Chuck Forsberg of
    * Omen Technology in Portland, Oregon)
    *
    * This function calculates the CRC used by the XMODEM/CRC Protocol
    * The first argument is a pointer to the message block.
    * The second argument is the number of bytes in the message block.
    * The function returns an integer which contains the CRC.
    * The low order 16 bits are the coefficients of the CRC.
    */

   int calcrc(ptr, count)
   char *ptr;
   int count;
   {
       int crc, i;

       crc = 0;

       while (--count >= 0) {
           crc = crc ^ (int)*ptr++ << 8;

           for (i = 0; i < 8; ++i)
               if (crc & 0x8000)
                   crc = crc << 1 ^ 0x1021;
               else
                   crc = crc << 1;
           }
       return (crc & 0xFFFF);
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -