Generate Hamming Code


#include<stdio.h>

int main()
{
int ab,db,ham,b[7],a[7],h[8],i,j,cb;
for(i=0;i<7;i++)
{
a[i]=0;
}
printf("\n\t\t\tSOFTWARE GENERATING HAMMING CODE");
//Asking For Number Hamming Code Is To Be Generated
printf("\n\n\tENTER THE NUMBER FOR WHICH YOU WANT TO GENERATE HAMMING CODE::");
scanf("%d",&ham);
//Displaying Number Entered
printf("\n\tTHE NUMBER FOR WHICH YOU WANT TO GENERATE HAMMING CODE::%d",ham);


//Converting Decimal Number Into Binary Number
for(i=0;ham>0;i++)
{
b[i]=(ham%2);
ham=(ham/2);

}

//Reversing The Number
for(j=0;(i-1)>=0;j++,i--)
{
a[j]=b[i-1];
}

//Calculating Hamming Code
h[7]=a[0];
h[6]=a[1];
h[5]=a[2];
h[3]=a[3];
h[1]=0;
h[2]=0;
h[4]=0;
h[1]=(h[3]^h[5]^h[7]);
h[2]=(h[3]^h[6]^h[7]);
h[4]=(h[5]^h[6]^h[7]);

//Printing Hamming Code
printf("\n\n\tHAMMING CODE::");
for(i=7;i>0;i--)
{
printf("%d",h[i]);
}
printf("\n");
return 0;
}



OUTPUT

SOFTWARE GENERATING HAMMING CODE

ENTER THE NUMBER FOR WHICH YOU WANT TO GENERATE HAMMING CODE::13

THE NUMBER FOR WHICH YOU WANT TO GENERATE HAMMING CODE::13

HAMMING CODE::1100110


Previous Post Next Post