You are on page 1of 2

//Program For Bit Stuffing Algorithm

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define mx 50
void main()
{
int st[mx],st1[mx],len,count=0,i,j,m=0;
clrscr();
printf("\n Enter the length:");
scanf("%d",&len);
printf("\n Enter bit pattern:");
for(i=0;i<len;i++)
scanf("%d",&st[i]);
for(i=0,j=0;i<len;i++,j++)
{
st1[j]=st[i];
if(st[i]==1)
count++;
else
count=0;
if(count==5)
{
st1[++j]=0;
m++;
count=0;
}
}
printf("\n BitStuff data is:");
for(i=0;i<len+m;i++)
printf("%d",st1[i]);
count=0;
for(i=0,j=0;i<len+m;i++,j++)
{
st[i]=st1[j];
if(st1[j]==1)
count++;
else
count=0;
if(count==5)
j++;
}
printf("\n Original Data is:");
for(i=0;i<len;i++)
printf("%d",st[i]);
getch();
}
/*OUTPUT*/
Enter the length:10
Enter bit pattern:0 0 1 1 1 1 1 1 1 1
BitStuff data is:00111110111
Original Data is:0011111111

You might also like