0% found this document useful (0 votes)
157 views5 pages

Example of Bit Stuffing

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

1.

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 .

Example of bit stuffing –


Bit sequence: 110101111101011111101011111110 (without bit stuffing)
Bit sequence: 110101111100101111101010111110110 (with bit stuffing)

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;

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\n");

for(i=0; i<j; i++)

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.

EX: WELCOME ( Befor 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);
}

printf("Enter the character\n");


scanf("%c",&ch);
ch=getchar();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy