当前位置:网站首页>CRC 校验
CRC 校验
2022-07-01 10:11:00 【@无聊人】
1. 概述:
该demo主要实现CRC校验
引用CRC库的地址为:https://github.com/whik/crc-lib-c
2. 测试:
/* demo_crc.c crc demo : CRC 校验 引用 crcLib.h crcLib.c github 地址 : https://github.com/whik/crc-lib-c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "crcLib.h"
int main(int argc, char *argv[]) {
char str[16] = "Hello World!";
printf("crc4_itu\t \"%s\" = 0x%0X\n", str, crc4_itu((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc5_epc\t \"%s\" = 0x%0X\n", str, crc5_epc((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc5_itu\t \"%s\" = 0x%0X\n", str, crc5_itu((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc5_usb\t \"%s\" = 0x%0X\n", str, crc5_usb((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc6_itu\t \"%s\" = 0x%0X\n", str, crc6_itu((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc7_mmc\t \"%s\" = 0x%0X\n", str, crc7_mmc((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc8\t\t \"%s\" = 0x%0X\n", str, crc8((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc8_itu\t \"%s\" = 0x%0X\n", str, crc8_itu((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc8_rohc\t \"%s\" = 0x%0X\n", str, crc8_rohc((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc8_maxim\t \"%s\" = 0x%0X\n", str, crc8_maxim((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_ibm\t \"%s\" = 0x%0X\n", str, crc16_ibm((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_maxim\t \"%s\" = 0x%0X\n", str, crc16_maxim((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_usb\t \"%s\" = 0x%0X\n", str, crc16_usb((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_modbus\t \"%s\" = 0x%0X\n", str, crc16_modbus((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_ccitt\t \"%s\" = 0x%0X\n", str, crc16_ccitt((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_ccitt_false\t \"%s\" = 0x%0X\n", str, crc16_ccitt_false((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_x25\t \"%s\" = 0x%0X\n", str, crc16_x25((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_xmodem\t \"%s\" = 0x%0X\n", str, crc16_xmodem((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc16_dnp\t \"%s\" = 0x%0X\n", str, crc16_dnp((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc32\t\t \"%s\" = 0x%0X\n", str, crc32((uint8_t *)str, (uint16_t)(strlen(str))));
printf("crc32_mpeg_2\t \"%s\" = 0x%0X\n", str, crc32_mpeg_2((uint8_t *)str, (uint16_t)(strlen(str))));
return 0;
}
#Makefile
CC := gcc
AR := ar
all:
$(CC) -c crcLib.c -o crcLib.o -Wall -Werror
$(AR) cr libcrcLib.a crcLib.o
#-L 指定库的路径 -l 指定需连接的库名
#-Wl,-Bstatic指示跟在后面的-lxxx选项链接的都是静态库
#-Wl,-Bdynamic指示跟在后面的-lxxx选项链接的都是动态库
$(CC) demo_crc.c -o demo_crc -lm -L. -Wl,-Bstatic -lcrcLib -Wl,-Bdynamic -Wall -Werror
clean:
rm demo_crc *.o *.a
边栏推荐
- leetcode:111. Minimum depth of binary tree
- 数字藏品市场新局面
- IDEA运行报错Command line is too long. Shorten command line for...
- 这样理解mmap,挺有意思!
- Tearful eyes, it's not easy to change jobs. Three rounds of interviews, four hours of soul torture
- C# [字节数组]与[16进制字符串]互相转换 - CodePlus系列
- Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
- 678. 有效的括号字符串
- 106. 从中序与后序遍历序列构造二叉树
- Venv: directory structure of venv
猜你喜欢

持续进阶,软通动力稳步推动云智能战略

Precautions for lvgl v8.2 string display on keil MDK (take little bear pie as an example)

Initial experience of Flink, a mainstream real-time stream processing computing framework

新数据库时代,不要只学 Oracle、MySQL

Today in history: the semiconductor war in the late 1990s; Von Neumann published the first draft; CBS acquires CNET

这样理解mmap,挺有意思!

Japanese professor sues Intel FPGA and SOC products for infringing a design patent

TC8:UDP_ USER_ INTERFACE_ 01-08

北汽蓝谷:业绩承压,极狐难期

云原生到底是什么?它会是未来发展的趋势吗?
随机推荐
大佬们 有没有搞过sink分流写入clickhouse 或者其他数据库的操作。
谁还在买“三只松鼠”们
树莓派4B系统搭建(超详细版)
IDEA运行报错Command line is too long. Shorten command line for...
Raspberry pie 4B system construction (ultra detailed version)
数字藏品市场新局面
7-Zip boycotted? The callers have committed "three crimes": pseudo open source, unsafe, and the author is from Russia!
直播管理项目
Who's still buying three squirrels
Write your own who commands
Common penetration tools -goby
4hutool practice: dateutil format time [easy to understand]
C# [字节数组]与[16进制字符串]互相转换 - CodePlus系列
tryhackme圣诞挑战2021-Advent of Cyber 3-day1-IDOR漏洞,不安全的访问控制漏洞
bash: ln: command not found
京东与腾讯续签三年战略合作协议;起薪涨至26万元!韩国三星SK争相加薪留住半导体人才;Firefox 102 发布|极客头条...
Comparison between Oracle JDK and openjdk
Can you afford to buy a house in Beijing, Shanghai, Guangzhou and Shenzhen with an annual salary of 1million?
BSN long story 10: how to ensure the safety of NFT
mysql cdc能把能把op字段拿出来吗