Thursday, 24 April 2014

WAP to demonstrate Parity bit for finding error

#include<stdio.h>
#include<conio.h>
int main()
{
    int a,i,j,n,ascii[20],rem=0,var,count=0,numzeros=0;
    int sum=0,x[20],z[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;   
    }
    for(i=1;i<=n;i++)
    {
                     var=0;
                     sum=0;
                     a=ascii[i];
                     count=0;
                     while(a>1) 
                     {                  
                     rem=a%2;
                     z[var]=rem;
                     if(rem==1)
                     {
                     count++;
                     }
                   
                     a=a/2;
                     var++;
                     }
                     z[var]=a;
                     if(var<7)
                     {
                        numzeros=7-var;
                        for(j=0;j<numzeros;j++)
                        {
                                            var++;
                                            z[var]=0;                                       
                        }    
                     }
                    
                     for(j=var;j>=0;j--)
                     {
                                        printf("%d",z[j]);
                     }
                      if(a==1)
                     {
                     count++;
                     }
                     if(count%2==0)
                     {
                                   printf("\t0\t");
                     }
                     else
                     {
                     printf("\t1\t");
                     }                 
    }
                    
    getch();

}

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016