Bit stuffing with flag 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<bits/stdc++.h>
using namespace std;
int main()
{
   char stuf[50],so[50],range[50];
   int i,j,count;
   cout<<"enter the data :";
   cin>>so;
   cout<<"enter the flag data :";
   cin>>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';
   cout<<"after bit stuffing : " <<range<<stuf<<range<<endl;
   return 0;

}

Output:



Bit stuffing with flag c++ Language Bit stuffing with flag c++ Language Reviewed by Saroar Zahan Sojib on February 22, 2019 Rating: 5

No comments:

ads
Powered by Blogger.