Shopping In MUMBAI

Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top. Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.

Wednesday, January 7, 2009

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
#include
#include
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{
a=pow(2,i);
if(a<=len)
{
max[i]=a;
count=count+1;
}
else
{
break;
}
}
printf("\nWe have to calculate ");
for(i=0;iprintf("r%d ",max[i]);
for(i=0;i{
flag=0;
n=0,c=0;
s=max[i];
printf("\nr%d =",max[i]);
for(j=s-1;j{
if(n{
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

*/

Program to Check & Correct the error in the data at the receiver’s end by implementing Hamming Code SocialTwist Tell-a-Friend

0 comments:

SUPPORT THIS BLOG