当前位置:网站首页>Implementation of CRC16 verification C language
Implementation of CRC16 verification C language
2022-07-18 05:16:00 【Summer night breeze_】
Cyclic redundancy check (Cyclic Redundancy Check, CRC) It is a kind of channel coding technology that generates short fixed digit check code according to data such as network packets or computer files , It is mainly used to detect or verify the possible errors after data transmission or saving . It uses the principle of division and remainder to detect errors .
This paper implements CRC16 Of C Language verification algorithm , It adopts the method of looking up tables .CRC Polynomials are x16+x15+x2+1(0x8005),CRC The initial value of 0xFFFF, yes modbus Of CRC Check algorithm .
1 crc.c
#include "crc16.h"
/* CRC16 The remainder table */
static uint16_t crctalbeabs[] = {
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
/*! * work can : CRC16 check * param1: Pointer to the data to be verified * param2: The length of the data to be verified * retval: Check the value obtained ,uint16_t type * * say bright : This time CRC Check to look-up table method , The polynomial is x16+x15+x2+1(0x8005),CRC The initial value of 0xFFFF */
uint16_t Crc16(uint8_t *ptr, uint32_t len)
{
uint16_t crc = 0xffff;
uint32_t i;
uint8_t ch;
for (i = 0; i < len; i++) {
ch = *ptr++;
crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4);
crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4);
}
return crc;
}
2 crc.h
#ifndef _CRC_H_
#define _CRC_H_
#include <stdint.h>
uint16_t Crc16(uint8_t *ptr, uint32_t len);
#define HIG_UINT16(a) ( ((a)>>8) & 0xFF )
#define LOW_UINT16(a) ( (a) & 0xFF )
#define HIG_UINT8(a) ( ((a)>>4) & 0x0F )
#define LOW_UINT8(a) ( (a) & 0x0F )
#endif /* crc.h */
边栏推荐
- 小白挑战学c语言第一天----运行环境的搭建
- STM32 IAP远程更新
- 电商平台后台管理系统--->系统详细设计(用户登录、商品管理模块)
- STM32F103 串口 +DMA中断实现数据收发
- v-bind和v-for
- FreeModbus 在 STM32F1 平台的移植和解析
- Uni app call function
- Information system project managers must recite the core examination points (I) six elements of the national information system
- 信息系统项目管理师核心考点(六)OSI协议的分层,导图+真题
- Redis02:Linux环境安装Redis
猜你喜欢

Niuke 2021 summer training 3-b-black and white

Information system project manager 10 days before the exam limit sprint + answer (7)

把后台拿到的数据渲染在页面上 对象与数组的渲染方式示例

Information system project manager 10 days before the exam limit sprint + answer (10): summary of comprehensive knowledge

hbuilder提交代码

Typora入门:全网最全教程

SourceInsight 插件使用

H5 cloud image background reading and writing CAD files - Online CAD, web CAD, web browsing and editing CAD

Niuke 2021 summer training 6-h-hopping rabbit

STM32F103 串口 +DMA中断实现数据收发
随机推荐
Niuke 2021 summer training 1-h-hash function
电商平台后台管理系统--->系统详细设计(用户登录、商品管理模块)
Core examination sites for information system project managers (VI) layering of OSI protocol, mapping + real questions
Redis03:Redis的5大常用数据类型
实现两个元素并排显示 (含flex一些属性的讲解)
Redis04: three special data types of redis
Huawei cloud stack opens its framework to the south to help ecological partners enter the cloud efficiently
Wechat applet from the beginning to the tenth day of learning ----- other operations of the applet
1 start.s分析
Matlab first learning
C # write a GUI tool and decompile it
Salesforce email sent to spam mailbox or SF email processing method not received (dkim - New CNAME version)
@tap是什么
Which is the safest financial platform? How about the income
理财平台哪个最安全收益怎么样
The difference between sx126x and sx127x
uni-app请求获取数据
CRC16校验
sx126x 与 sx127x 的区别
MATLAB初次学习