5.
Bit Stuffing
AIM: To understand the concept of Bit Stuffing using C program.
Bit stuffing is the insertion of one or more bits into a transmission unit as a way to provide signaling
information to a receiver. The receiver knows how to detect and remove or disregard the stuffed bits. This
is used when a communication protocol requires a fixed frame size. Bits are inserted to make the frame
size equal to the defined frame size.
Fig: Example of Bit Stuffing
C program to illustrate Bit Stuffing
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size (Example: 8):");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
if(a[i]==1)
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
j++;
b[j]=a[k];
count++;
if(count==5)
j++;
b[j]=0;
i=k;
}
else
b[j]=a[i];
i++;
j++;
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
getch();
OUTPUT FOR BIT STUFFING:
Enter frame size (Example: 8): 12
Enter the frame in the form of 0 and 1: 0 1 0 1 1 1 1 1 1 0 0 1
After Bit Stuffing: 0101111101001
RESULT: We have successfully implemented the C program and understood the concept of Bit Stuffing.