Hamming Code

/*
* Title: Implementation of Hamming code for error dection and correction
* Name: Akshay Thakare
* Roll No: 6790
*/

#include
#include
void check(int d[],int x[])
{
	x[0]=(d[3]+d[5]+d[7]+d[9]+d[11])%2;
	x[1]=(d[3]+d[6]+d[7]+d[10]+d[11])%2;
	x[2]=(d[7]+d[5]+d[6]+d[12])%2;
	x[3]=(d[9]+d[10]+d[11]+d[12])%2;
}

int main()
{
	int a[13],b[13],i,j,c=1,f=0,x[4],x1[4];
	printf("Enter data bits\n");
	for(i=12;i>2;i--)
	{
		if(i==4||i==8)
			continue;
		scanf("%d",&a[i]);
	}
	check(a,x);
	for(i=0,j=1;i0;i--)
		printf("%d",a[i]);
	printf("\nEnter recived code\n");
	for(i=12;i>=1;i--)
		scanf("%d",&b[i]);
	check(b,x1);
	for(i=0,j=0;i0;i--)
			printf("%d",b[i]);
	}
	else
		printf("Recived code is right\n");
}
/*
Output 1
Enter data bits
0 0 1 1 1 0 0 1
Sent code is
001101001111
Enter recived code
0 0 1 1 0 1 1 0 1 1 1 1
Error in 6th position
Corrected code is 
001101001111

Output 2
Enter data bits
0 1 0 1 1 0 1 1
Sent code is
010101010111
Enter recived code
0 0 0 1 0 1 0 1 0 1 1 1
Error in 11th position
Corrected code is 
010101010111

Output 3
Enter data bits
0  0 1 1 1 0 0 1
Sent code is
001101001111
Enter recived code
0 0 1 1 0 1 0 0 1 1 1 1
Recived code is right

*/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s