Thursday, 24 April 2014

WAP to demonstrate CRC bit for finding error

#include<stdio.h>
#include<conio.h>
int main()
{
    int i,j,l,sizeI,sizeG,input[20],generator[20],num,k,m,n,x,num1;
    printf(" size of input bits :\t");
    scanf("%d",&sizeI);
    printf("enter the input bits\n");
    for(i=0;i<sizeI;i++)
    scanf("%d",&input[i]);
    printf("size of generator : \t");
    scanf("%d",&sizeG);
    printf("enter the generator bits\n");
    for(i=0;i<sizeG;i++)
    scanf("%d",&generator[i]);
    num=sizeI+sizeG-1;
    num1=num+4;
    int mat[num1][num];
    for(i=0;i<num;i++)
    {
    mat[0][i]=0;
    if(i<sizeI)
    mat[0][i]=input[i];
    }
    x=0;
    for(i=0;i<num1;i=i+2)
    {
                      l=0;
                      j=x;
                       if(mat[i][j]==0)
                       {
                                        for(j=x;j<sizeG+x;j++)
                                        {                               
                                    mat[i+1][j] = 0;                                                                    
                                    }
                       }
                       else
                       {                                   
                      for(j=x;j<sizeG+x;j++)
                      {
                               
                                    mat[i+1][j] =   generator[l];
                                    l++;                                   
                      }
                      }
                      for(k=x;k<sizeG+x; k++)
                      {
                                  m=  mat[i][k];
                                  n= mat[i+1][k];
                                  if(m==0 && n==0)
                                  {
                                          mat[i+2][k]=0;
                                  }
                                  else if(m==0 && n==1)
                                  {
                                       mat[i+2][k]=1;
                                  }
                                  else if(m==1 && n==1)
                                  {
                                       mat[i+2][k]=0;
                                  }
                                  else
                                  {
                                          mat[i+2][k]=1;                                             
                                  }   
                      }
                      mat[i+2][k]=mat[0][k];
                      x++;
    }
    for(i=num1-1;i<num1;i++)
    {
                      for(j=num-(sizeG-1) ;j<num;j++)
                      {                                  
                                  mat[0][j]=mat[i][j];                                    
                      }                     
    }
    printf("final code is\n");
    for(j=0 ;j<num;j++)
    {
            printf("%d\t",mat[0][j]);
    }                       
    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