Error Correction-Hamming Code
Error Correction-Hamming Code
Ex.No:
Date:
Aim:
To implement the Error Detection / Error Correction Techniques using Hamming code
Procedure:
1. Get Sending data in array
2. Get receiving data in another array
3. Calculate encoded data using hamming algorithm
4. Enter the received data
5. Check whether data is received with error or not using Hamming algorithm
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int data[7],rec[7],i,c1,c2,c3,c;
printf("Error detection and correction by Hamming Code for message of 4 bits in size \n enter
message bit one by one:");
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("the encoded bits are given below:\n");
for (i=0;i<7;i++)
{
printf("%d",data[i]);
}
printf("\n enter the received data bits one by one:");
for (i=0;i<7;i++)
{
scanf("%d",&rec[i]);
}
c1=rec[6]^rec[4]^rec[2]^rec[0];
c2=rec[5]^rec[4]^rec[1]^rec[0];
c3=rec[3]^rec[2]^rec[1]^rec[0];
c=c3*4+c2*2+c1 ;
if(c==0)
{
printf("\n there is no error in transmission : ");
}
else
{
printf("\n error on the postion: %d \n the 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:
When no error in transmission
Result:
Thus the implementation of Error Detection / Error Correction Technique was implemented and output is
verified