DCCN
DCCN
#include<stdio.h>
char data[20],div[20],temp[4],total[100]; int
i,j,datalen,divlen,len,flag=1;
main()
{
printf("Enter the total bit of data:");
scanf("%d",&datalen);
scanf("%d",&divlen);
len=datalen+divlen-1; printf("\nEnter
for(i=0;i<datalen;i++)
{
total[i]=data[i];
temp[i]=data[i];
}
for(i=datalen;i<len;i++)
//padded with zeroes corresponding to divlen total[i]='0';
check(); // check forcrc
temp[i+datalen]=data[i];
printf("\ntransmitted Code Word:%s",temp);
printf("\n\nEnter the received code word:");
scanf("%s",total);
check();
for(i=0;i<divlen-1;i++)
if(data[i]=='1')
{
flag=0; break;
}
if(flag==1)
printf("\nsuccessful!!");
else
printf("\nreceived code word contains errors...\n");
}
void check()
{
for(j=0;j<divlen;j++)
data[j]=total[j];
while(j<=len)
{
if(data[0]=='1')
// in XOR ans remains as it is except in case of 1
for(i = 1;i <divlen ; i++)
data[i] = (( data[i] == div[i])?'0':'1');
for(i=0;i<divlen-1;i++)
data[i]=data[i+1];
data[i]=total[j++];
// replace empty right by total
}
}
OUTPUT:
Hamming code:
#include<stdio.h>
#include<conio.h>
void main() {
int data[7],rec[7],i,c1,c2,c3,c;
scanf("%d%d%d%d",&data[0],&data[1],&data[2],&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];
printf("\nthe encoded bits are given below: \n");
for (i=0;i<7;i++)
{
printf("%d ",data[i]);
}
if(c==0)
{
printf("\ncongratulations there is no error: ");
}
else
{
printf("\nerron on the postion: %d\nthe correct message is \n",c);
if(rec[7-c]==0)
rec[7-c]=1; else rec[7-c]=0;
for (i=0;i<7;i++)
{
printf("%d ",rec[i]);
}
}
getch();
}
OUTPUT: