Loop Control Statements 167
6. 51 Write a program to find the Hamming code for the entered binaiy code. Assume the
binary code of four bits in length. The hamming code should be seven bits.
Up: R.W. Hamming developed error correcting and detecting codes in communicating the
four bits data which is to be transmitted contains additional three check bits. The word that
is to be transmitted, its format, will be D7, D6, D5, P4, D3, P2 & PI. Where D bits are data bits
and the P bits are parity bits. PI is set so that it provides even parity over bits PI, D3, D5 &
D7. P2 is set for even parity over bits P2, D3, D6 & D7. P4 is set for even parity over bit3
P4,D5,D6 & D7
# include <stdio.h>
# include <conio.h>
void main()
{
s t a t ic int c [7 ];
in t x ,b [4];
c l r s c r ();
printf ("n Read the Binary Numbers:");
fo r (x=0;x<4;x++)
scanf (“%d",&cb[x]);
I*piece copy operation */
c[0]=b[0];
c[l]=b[lj;
c[2]=b[2J;
c[4]=b[3J;
printf ("n Before XOR operation: “);
fo r (x=0;x<=6;x++)
printf ("%3d",c[x]);
c[6]= c[0]*c[2]*c[4];
c[5]= c[0]Ac[l]Ac[4J;
c[3]= c[0]*c[l]*c[21;
printf ("n Hamming code after XOR operation:");
for (x=0;x<=6;x++)
printf ("%3d",c[xl);
getcheO;
I
OUTPUT:
Read the Binary Numbers : 1 0 1 0
Before XOR operation : 1 0 1 0 0 0 0
Hamming code after XOR operation : 1 0 1 0 0 1 0