c++计算 char数组CRC算法
2020-12-13 03:49
阅读:404
标签:code win7 判断 creat class null i+1 校验 row
我使用的OS:win7。
我使用的开发环境:VS2010 + sp1
算法源码:
unsigned int create_crc_2(unsigned char *parr, unsigned int parr_len) { unsigned char *pbuf = NULL; // 数据长度为奇数,在数据前补0 if (1 == parr_len % 2) { parr_len += 1; pbuf = new(std::nothrow) unsigned char[parr_len]; memset(pbuf, 0, parr_len); memcpy(&pbuf[1], parr, parr_len - 1); } // 数据长度为偶数,原样复制数据 else { pbuf = new(std::nothrow) unsigned char[parr_len]; memcpy(pbuf, parr, parr_len); } // CRC为用来移位的32位数据结构,ploy为32位的生成多项式 unsigned long crc = 0, ploy = 0; // CRC余数值 unsigned int crc_code = 0; int i = 0, j = 0, k = 0; // crc = 0xFFFF0000 // crc校验初始值为0 crc = 0; ploy = 0x80000000; // 求得32位的生成多项式 ploy = ploy ^ ((unsigned long)PLOYNOMAL > 16); // 清除缓冲 if (NULL != pbuf) { delete [] pbuf; pbuf = NULL; } // 返回计算结果 return crc_code; }
c++计算 char数组CRC算法
标签:code win7 判断 creat class null i+1 校验 row
原文地址:https://www.cnblogs.com/pandamohist/p/11089116.html
评论
亲,登录后才可以留言!