本文介绍: 函数返回计算得到的CRC-32值。

crc32函数原型

uint32_t crc32(uint32_t crc, const Bytef *buf, uInt len);

参数说明

返回

函数返回计算得到的CRC-32值。

注意事项

示例代码

/* crc32.c */

#include <stdio.h&gt;  
#include <stdint.h&gt;  
#include <string.h&gt;  
#include <zlib.h&gt;  
  
int main() {  
    uint8_t data[] = {0x01, 0x02, 0x03, 0x04};  
    size_t data_length = sizeof(data);  
      
    uint32_t crc = crc32(0xFFFFFFFF, data, data_length);  
    crc ^= 0xFFFFFFFF; // 取反操作  
      
    printf("CRC-32 value: 0x%08Xn", crc);  
      
    return 0;  
}

Debian10安装zlib库

# apt install zlib1g-dev
The following packages have unmet dependencies:
 zlib1g-dev : Depends: zlib1g (= 1:1.2.11.dfsg-1) but 1:1.2.11.dfsg-1+deb10u2 is to be installed
E: Unable to correct problems, you have held broken packages.

# apt install zlib1g=1:1.2.11.dfsg-1
The following packages will be DOWNGRADED:
  zlib1g
0 upgraded, 0 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.

# apt install zlib1g-dev
The following NEW packages will be installed:
  zlib1g-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.

编译运行

# gcc -lz crc32.c
# ./a.out
CRC-32 value: 0x977824D1

原文地址:https://blog.csdn.net/eidolon_foot/article/details/134603111

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_1789.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注