CRC32校验的c语言实现
时间: 2023-11-25 12:07:38 浏览: 97
CRC校验C语言实现
好的,以下是CRC32校验的C语言实现代码:
```c
#include <stdio.h>
#include <stdint.h>
uint32_t crc32(uint8_t *data, uint32_t length) {
uint32_t crc = 0xFFFFFFFF;
for (uint32_t i = 0; i < length; i++) {
crc ^= data[i];
for (uint32_t j = 0; j < 8; j++) {
if (crc & 1) {
crc = (crc >> 1) ^ 0xEDB88320;
} else {
crc >>= 1;
}
}
}
return ~crc;
}
int main() {
uint8_t data[] = "hello world";
uint32_t crc = crc32(data, sizeof(data) - 1);
printf("CRC32: %08X\n", crc);
return 0;
}
```
阅读全文