没有合适的资源?快使用搜索试试~ 我知道了~
首页海明码和CRC校验的C语言实现
海明码和CRC校验的C语言实现 1.海明码 //code by zxf 2010.4.10 #include <stdio.h> #include <conio.h> #include <math.h> //N代表待编码数据的上限位数 #define N 100 int HmLength(int k);//计算海明码校验位位数 void InCode(char *data,char *c,int k,int r);//计算海明码每个校验位的数值 void main() {
资源详情
资源评论
资源推荐

海明码和 CRC 校验的 C 语言实现
1.海明码
//code by zxf 2010.4.10
#include <stdio.h>
#include <conio.h>
#include <math.h>
//N 代表待编码数据的上限位数
#define N 100
int HmLength(int k);//计算海明码校验位位数
void InCode(char *data,char *c,int k,int r);//计算海明码每个校验位的数值
void main()
{
int k=0,r=0,dnum=0,cnum=0;
char data[N];
char c[N];
clrscr();
printf("Now please input the data you want to Incode:");
for(k=0;k<N;k++)//循环输入待编码数据并记录数据长度,遇到非'1'非'0'输入结束输入
{
data[k]=getche();
if(data[k]!='0'&&data[k]!='1')
{
break;
}
}
printf("__________________________________________________________");
r=HmLength(k);//求取校验位数
printf("k=%d r=%d The length of Hamming code=%d",k,r,r+k);//输出海明码相关位数信息
InCode(data,c,k,r);//计算海明码
printf("The Hamming code is:");
for(int j=1;j<r+k+1;j++)//组合输出数据和校验码
{
if(j==(int)pow(2,cnum))
{
printf("%c",c[cnum]);
cnum++;

















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0