Advertisement

CRC-32循环冗余校验算法开发和实现

阅读量:

C

复制代码
    #include <inttypes.h>
    #include <stdio.h>
    #include <string.h>
     
    uint32_t
    rc_crc32(uint32_t crc, const char *buf, size_t len)
    {
    	static uint32_t table[256];
    	static int have_table = 0;
    	uint32_t rem;
    	uint8_t octet;
    	int i, j;
    	const char *p, *q;
     
    	/* This check is not thread safe; there is no mutex. */
    	if (have_table == 0) {
    		/* Calculate CRC table. */
    		for (i = 0; i < 256; i++) {
    			rem = i;  /* remainder from polynomial division */
    			for (j = 0; j < 8; j++) {
    				if (rem & 1) {
    					rem >

全部评论 (0)

还没有任何评论哟~