1 Star 0 Fork 1

东海龙子/QT_EMB_RES_PACK

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mycrc.cpp 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
东海龙子 提交于 2024-07-15 03:49 . 初步上传
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dhlz/qt_-emb_-res_-pack.git
[email protected]:dhlz/qt_-emb_-res_-pack.git
dhlz
qt_-emb_-res_-pack
QT_EMB_RES_PACK
master

搜索帮助