⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc.cpp

📁 16位CRC的c语言实现。并编写了测试程序
💻 CPP
字号:
/*
 |
 | Copyright disclaimer:
 |   This software was developed at the National Institute of Standards
 |   and Technology by employees of the Federal Government in the course
 |   of their official duties. Pursuant to title 17 Section 105 of the
 |   United States Code this software is not subject to copyright
 |   protection and is in the public domain.
 |
 |   We would appreciate acknowledgement if the software is used.
 |
*/

/*
 | Project:     WCDMA simulation environment
 | Module:      Test bed for CRC routines.
 | Author:      Tommi Makelainen, Nokia/NIST
 | Date:        January 27, 1999
 |
 | History:
 |              January 27, 1999 Tommi Makelainen
 |                      Initial version.
 |
 |              March 24, 1999 Tommi Makelainen
 |                      Input data for crc calculation from char to int.
 |在发射端对K位数据加入r位CRC校验码,形成k+r位数据,在接受端对这k+r位数据再进行CRC校验码计算,若计算所得CRC为0,则接收无误。
  在接收端计算CRC时,先计算k位数据的CRC,再计算r为CRC的CRC。设计算k位数据的CRC为AA51,根据字节计算CRC( crc_value = (crc_value<<8) ^ crctable[(crc_value>>8) ^ data_byte])的方法,在计算r位CRC的CRC可得
  k+r位数据的校验码为0.
*/

#include <stdio.h>
#include <math.h>
#include "crc.h"
//#include "crc1.cpp"

#define INPUT_SIZE 200
#define ARIB_CRC16 0x11021

int tc_block_sizes[] = {60, 100, 120, 200};

int main(int argc, char *argv[])
{
    int i, j;
    int test_input[8], test_input2[24];
    int test_inp_size;
    unsigned short crc,crc_value,crc_value1;
    int crc_bits[16];
	

    test_inp_size = 8;
    for (i=0; i < test_inp_size; i++) {
        test_input[i] = (i+1) % 2;
    }

    wcdma_crctable_init (ARIB_CRC16);
    /*wcdma_crctable_init (0x1321); */
    crc_value = wcdma_calc_crc(test_input, test_inp_size); 
    //crc_value = wcdma_get_crc_value(test_input, test_inp_size, crc_bits);
    printf("CRC value %x\n", crc_value);

   for (i=0; i < test_inp_size; i++) {
        test_input2[i] = test_input[i];
    }
    /*for (i=test_inp_size, j=0; i < (test_inp_size+16); i++, j++) {
        test_input2[i] = crc_bits[j];
    }*/

    test_input2[test_inp_size] = (crc_value<<16) & 0xffff0000; //校验码要紧跟在数据的后面
    crc_value1 = wcdma_calc_crc(test_input2, test_inp_size+1); 
	printf("CRC bits in decoding: %x\n", crc_value1);

    /*wcdma_get_crc_value(test_input2, test_inp_size+16, crc_bits);

    printf("CRC bits in decoding: ");
    for (i=0; i < 16; i++) {
        printf("%x ", crc_bits[i]);
    }
    printf("\n");*/

    return;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -