Headlines
Loading...
Data Communication network(DCN) Program to Check & Correct the error in the data at the receiver’s end by implementing  Hamming Code

Data Communication network(DCN) Program to Check & Correct the error in the data at the receiver’s end by implementing Hamming Code

Program to Check & Correct the error in the data at the receiver’s end by implementing  Hamming Code 

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int len,bit[100],i,count=0,sum=0,a,n,j,c=0,s,flag=0,z;
long max[10];
clrscr();
printf("enter the len of string");
scanf("%d",&len);
printf("Enter the bit stream");
for(i=len-1;i>=0;i--)
scanf("%d",&bit[i]);
for(i=len-1;i>=0;i--)
printf("\n%d-%d",i+1,bit[i]);
for(i=0;i<len;i++)
{
a=pow(2,i);
if(a<=len)
{
max[i]=a;
count=count+1;
}
else
{
break;
}
}
printf("\nWe have to calculate ");
for(i=0;i<count;i++)
printf("r%d  ",max[i]);
for(i=0;i<count;i++)
{
flag=0;
n=0,c=0;
s=max[i];
printf("\nr%d =",max[i]);
for(j=s-1;j<len;j++)
{
if(n<s && flag==0)
{
n=n+1;
if(bit[j]==1)
{
c=c+1;
}
printf("%d",bit[j]);
}
else
{
n=n-1;
flag=1;
if(n==0)
{   flag=0;  }
}
}
if(c%2!=0)
{
sum=sum+max[i];
}
}
if(sum==0)
printf("\nThere is no error");
else
printf("\nError is at bit position %d ",sum);
if(bit[sum-1]==0)
{
bit[sum-1]=1;
}
else
{
bit[sum-1]=0;
}
printf("\nOriginal data stream is ");
for(i=len-1;i>=0;i--)
{
z=pow(2,count-1);
if(i==(z-1))
{
count--;
}
else
{
printf("%d",bit[i]);
}
}
getch();
}
Output:
enter the len of string11
Enter the bit stream1                                                           
0                                                                               
1                                                                               
1                                                                               
0                                                                               
1                                                                               
0                                                                               
1                                                                               
1                                                                               
0                                                                               
1                                                                               
                                                                                
11-1
10-0
9-1
8-1
7-0
6-1
5-0
4-1
3-1
2-0
1-1
We have to calculate r1  r2  r4  r8
r1 =110011
r2 =011001
r4 =1010
r8 =1101
Error is at bit position 10
Original data stream is 1110101


enter the len of string11
Enter the bit stream1                                                           
0                                                                               
0                                                                               
1                                                                               
1                                                                               
0                                                                               
1                                                                               
0                                                                               
1                                                                               
1
0
                                                                                
11-1                                                                            
10-0                                                                            
9-0                                                                             
8-1                                                                             
7-1                                                                             
6-0                                                                             
5-1                                                                             
4-0                                                                             
3-1                                                                             
2-1                                                                             
1-0                                                                             
We have to calculate r1  r2  r4  r8                                             
r1 =011101                                                                      
r2 =110101                                                                      
r4 =0101                                                                        
r8 =1001                                                                        
There is no error                                                      
Original data stream is 1001011                                                 
                                                                                
*/

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***