#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k,M[10],C[10],G[10][10],par[10][10];
clrscr();
printf(" For A Generator Matrix Enter :\n");
printf("1. The No Of Message Bits(n)\t: ");
scanf("%d",&n);
printf("2. The No Of Parity Bits(k)\t: ");
scanf("%d",&k);
printf("\nEnter the parity matrix: \n");
for(i=0;i<k;i++)
for(j=k;j<n;j++)
scanf("%d",&par[i][j]);
printf("\n Generator matrix \n");
for(i=0;i<k;i++)
{
for(j=0;j<n;j++)
{
if(j<k)
{
if(i==j)
{
G[i][j]=1;
printf("%d\t",G[i][j]);
}
else
{
G[i][j]=0;
printf("%d\t",G[i][j]);
}
}
else
{ G[i][j]=par[i][j];
printf("%d\t",G[i][j]);
}
}
printf("\n");
}
printf("\nEnter The Message Bits\n");
for(i=0;i<k;i++)
scanf("%d",&M[i]);
printf("\t\t\tResult\n");
printf("\n\tThe Generator Matrix Is :\n\t");
for(i=0;i<k;i++)
{
for(j=0;j<n;j++)
printf("%d\t",G[i][j]);
printf("\n\t");
}
printf("\n\tThe Parity Matrix Is :\n\t");
for(i=0;i<k;i++)
{
for(j=0;j<n-k;j++)
{
par[i][j]=G[i][j+k];
printf("%d\t",par[i][j]);
}
printf("\n\t");
}
printf("\n\tThe Messege Bits :\n\t");
for(i=0;i<k;i++)
printf("%d ",M[i]);
for(i=0;i< n-k;i++)
{
C[i] = 0;
for(j=0;j< k;j++)
C[i]=(C[i]+M[j]*par[j][i])%2;
}
printf("\n\n\tCode Word For Given Messege Bit:\n\t");
for(i=0;i<k;i++)
printf("%d",M[i]);
for(i=0;i<n-k;i++)
printf("%d",C[i]);
getch();
}
Output:
For A Generator Matrix Enter :
1. The No of Message Bits(n) : 7
2. The No of Parity Bits(k) : 4
Enter the parity matrix:
1
1
0
0
1
1
1
1
1
1
0
1
Generator matrix
1 0 0 0 1 1 0
0 1 0 0 0 1 1
0 0 1 0 1 1 1
0 0 0 1 1 0 1
Enter The Message Bits
1
0
0
0
Result
The Generator Matrix Is :
1 0 0 0 1 1 0
0 1 0 0 0 1 1
0 0 1 0 1 1 1
0 0 0 1 1 0 1
The Parity Matrix Is :
1 1 0
0 1 1
1 1 1
1 0 1
The Messege Bits :
1 0 0 0
Code Word For Given Messege Bit:
1 0 0 0 1 1 0
No comments:
Post a Comment