#include<stdio.h>
#include<conio.h>
int main()
{
int a,i,j,n,ascii[20],rem=0,var,count=0,numzeros=0,totalsum=0,p,q;
int sum=0,x[20],z[20],code[20];
char str[20];
printf("enter the word
length\n");
scanf("%d",&n);
printf("enter the word : \t");
for(i=0;i<=n;i++)
{
scanf("%c",&str[i]);
}
for(i=1;i<=n;i++)
{
j=str[i];
ascii[i]=j;
totalsum=totalsum+j;
}
if(totalsum>256)
{
p=totalsum%256;
q=totalsum/256;
totalsum=p+q;
}
ascii[i]=totalsum;
printf("----------Binary Values for
entered text----------\n");
for(i=1;i<=n+1;i++)
{
var=0;
sum=0;
a=ascii[i];
count=0;
while(a>1)
{
rem=a%2;
z[var]=rem;
a=a/2;
var++;
}
z[var]=a;
if(var<7)
{
numzeros=7-var;
for(j=0;j<numzeros;j++)
{
var++;
z[var]=0;
}
}
if(i!=(n+1))
{
for(j=var;j>=0;j--)
{
printf("%d",z[j]);
}
printf("(%c)",ascii[i]);
}
else
{
for(j=var;j>=0;j--)
{
printf("%d",z[j]);
}
printf("--->
(Addition of binary values)\n");
}
printf("\n");
}
printf("Generated code is \n");
for(j=var;j>=0;j--)
{
if(z[j]==0)
code[j]=1;
else
code[j]=0;
printf("%d",code[j]);
}
printf("\n--------------------------------------------------\n\n");
printf("----------In
receiver side : ---------------------\n");
for(j=var;j>=0;j--)
{
printf("%d",z[j]);
}
printf("--->
(Addition of binary values)\n");
for(j=var;j>=0;j--)
{
printf("%d",code[j]);
}
printf("--->
(Generated code word)\n");
printf("--------------------------------------------------\n");
printf("11111111 ---->addition
operation\n");
printf("after
complement operation\n");
printf("00000000
---->no error found\n");
getch();
}
No comments:
Write comments