代码拉取完成,页面将自动刷新
#include "mycrc.h"
mycrc::mycrc(void)
{
reset();
}
mycrc::~mycrc()
{
}
void mycrc::reset(void)
{
crc16 = 0xFFFF;
crc32 = 0xFFFFFFFF;
}
void mycrc::push(void const *p_data, unsigned long size)
{
crc16 = crc16_compute(p_data, size, &crc16);
crc32 = crc32_compute(p_data, size, &crc32);
}
unsigned short mycrc::value16(void)
{
return crc16;
}
unsigned long mycrc::value32(void)
{
return crc32;
}
unsigned short mycrc::crc16_compute(void const *p_data, unsigned long size, unsigned short const *p_crc)
{
unsigned short crc = *p_crc;
unsigned char const *data = (unsigned char const *)p_data;
for (unsigned long i = 0; i < size; i++)
{
crc = (unsigned char)(crc >> 8) | (crc << 8);
crc ^= data[i];
crc ^= (unsigned char)(crc & 0xFF) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xFF) << 4) << 1;
}
return crc;
}
unsigned long mycrc::crc32_compute(void const *p_data, unsigned long size, unsigned long const *p_crc)
{
unsigned long crc;
unsigned char const *data = (unsigned char const *)p_data;
crc = ~(*p_crc);
for (unsigned long i = 0; i < size; i++)
{
crc = crc ^ data[i];
for (int j = 8; j > 0; j--)
{
crc = (crc >> 1) ^ (0xEDB88320U & ((crc & 1) ? 0xFFFFFFFF : 0));
}
}
return ~crc;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。