Bit stuffing in C Language


Bit stuffing is the insertion of non information bits into data. Note that stuffed bits should not be confused with overhead bits. Overhead bits are non-data bits that are necessary for transmission.

#include<stdio.h>
int main()
{
   char stuf[50],so[50],range[50];
   int i,j,count;

   printf("enter the data :");
   scanf("%s",so);
   printf("enter the flag data :");
   scanf("%s",range);
   count=0,j=0;
   for(i=0;i<strlen(so);i++)
   {
       if(so[i]=='1')
       {
           count++;
       }
       else
       {
           count=0;
       }
       stuf[j]=so[i];
       j++;
       if(count==5 && so[i+1]=='1')
       {
           stuf[j]='0';
           j++;
           count=0;
       }
   }
   stuf[j]='\0';
   printf("after bit stuffing : %s %s %s",range,stuf,range);
   return 0;

}

output:



Bit stuffing in C Language Bit stuffing in C Language Reviewed by Saroar Zahan Sojib on February 22, 2019 Rating: 5

No comments:

ads
Powered by Blogger.