Thursday, 24 April 2014

4. WAP to demonstrate Bit stuffing in framing

#include<stdio.h>
#include<conio.h>
int main()
{
    int i,count,InputValue[30],TotalNumbers,OutputValue[30],SizeOfInput,j,SizeOfOutput=1;
    printf("---------------BIT STUFFING------------\n:");
    printf("enter the size of input\n:");
    scanf("%d",&SizeOfInput);
    printf("enter the input number of size %d\n",SizeOfInput);
    for(i=1;i<=SizeOfInput;i++)
    {
                               scanf("%d",&InputValue[i]);
    }
     for(i=1;i<=SizeOfInput;i++)
    {
                          if( InputValue[i]==1 && InputValue[i+1]==1 && InputValue[i+2]==1 && InputValue[i+3]==1 && InputValue[i+4]==1)
                          {
                              for(j=i;j<=i+4;j++)
                              {
                                            OutputValue[SizeOfOutput]=   InputValue[j];
                                            SizeOfOutput++;
                              } 
                               OutputValue[SizeOfOutput]=0;
                               SizeOfOutput++;
                              i=i+4;
                          }
                          else
                          {
                               OutputValue[SizeOfOutput]=  InputValue[i];
                               SizeOfOutput++;
                          }            
    }
    printf("\n\n-------bit Stufffing encoding----------\n");
for(i=1;i<SizeOfOutput;i++)
    {
                               printf("%d\t",OutputValue[i]);
    }
    SizeOfInput=1;
    printf("\n \n \n-------bit unStufffing----------\n");
    for(i=1;i<SizeOfOutput;i++)
    {
                               if( OutputValue[i]==1 && OutputValue[i+1]==1 && OutputValue[i+2]==1 && OutputValue[i+3]==1 && OutputValue[i+4]==1 && OutputValue[i+5]==0)
                          {
                              for(j=i;j<=i+4;j++)
                              {
                                            InputValue[SizeOfInput]=   OutputValue[j];
                                            SizeOfInput++;
                              }    
                              i=i+5;
                          }
                          else
                          {
                               InputValue[SizeOfInput]=  OutputValue[i];
                               SizeOfInput++;
                          }            
    }
      for(i=1;i<=SizeOfInput-1;i++)
    {
                               printf("%d\t",InputValue[i]);
    }
    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