Example of Bit Stuffing
Example of Bit Stuffing
Example of Bit Stuffing
Implement the data link layer framing methods such as character, character
stuffing and bit stuffing.
a) Bit Stuffing:
The new technique allows data frames to contain an ar bitrary number if bits and
allows character codes with an arbitrary no of bits per character. Each frame begins
and ends wit h special bit pattern, 011 11110, called a flag byte. When ever the
sender ’s data link layer enc ounters five consecutive ones in the dat a , it
automatically stuffs a 0 b itin to the out going bit stream .
After 5 consecutive 1-bits, a 0-bit is stuffed. Stuffed bits are marked bold.
Program:
#include<stdio.h>
#include<string.h>
int main()
int a[20],b[30],i,j,k,count,n;
scanf("%d",&n);
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
if(a[i]==1)
b[j]=a[i];
j++;
b[j]=a[k];
count++;
if(count==5)
j++;
b[j]=0;
i=k;
else
{
b[j]=a[i];
i++;
j++;
printf("%d \n",b[i]);
return 0;
Output:
1 b) Byte Stuffing:
The framing method gets around the problem of resynchronization after an error by
havi ng each frame start with the AS II character sequence DLE STX and the
sequence DLE ETX. If the destination ever losses the track of the frame
boundaries all it has to do is look for DLE STX or DLE ETX characters to figure
out. The data link l ayer on the receiving end removes the DLE before the data are
given to t h e network layer. This technique is called character stuffing.
DLESTXWELCOMEDLEETX
Program:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("Enter string\n");
scanf(" %s",a);
n=strlen(a);
printf("Enter position\n");
scanf("%d",&pos);
//printf("Enter the character\n");
//scanf("%c",&ch);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);
}