0% found this document useful (0 votes)
2K views17 pages

1.character Stuffing Bit Stufffing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views17 pages

1.character Stuffing Bit Stufffing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Bit Stuffing & Byte

Stuffing
• In Data Link layer, the stream of bits from physical layer are divided
into data frames.
• The data frames can be of fixed length or variable length.
• In variable – length framing, the size of each frame to be transmitted
may be different.
• So, a pattern of bits is used as a delimiter to mark the end of one
frame and the beginning of the next frame.
The two common approaches are −

• Byte – Stuffing − A byte is stuffed in the message to differentiate from


the delimiter. This is also called character-oriented framing.

• Bit – Stuffing − A pattern of bits of arbitrary length is stuffed in the


message to differentiate from the delimiter. This is also called bit –
oriented framing.
Algorithm for Character stuffing

1. Start
2. Append DLE STX at the beginning of the string
3. Check the data if character is present; if character DLE is present in
the string
(example DOODLE) insert another DLE in the string (ex: DOODLEDLE)
4. Transmit DLE ETXat the end of the string
5. Display the string
6. Stop
Frame in a Character – Oriented
Framing
• In character – oriented protocols, the message is coded as 8-bit characters, using codes like
ASCII codes.

A frame has the following parts −

• Frame Header − It contains the source and the destination addresses of the frame.

• Payload field − It contains the message to be delivered.

• Trailer − It contains the error detection and error correction bits.

• Flags − 1- byte (8-bits) flag at the beginning and at end of the frame. It is a protocol –
dependent special character, signalling the start and end of the frame.
• In character – oriented protocol, the mechanism adopted is byte
stuffing.
• In byte stuffing, a special byte called the escape character (ESC) is
stuffed before every byte in the message with the same pattern as the
flag byte.
• If the ESC sequence is found in the message byte, then another ESC
byte is stuffed before it.
#include<stdio.h>
#include<string.h> if(d[i]=='D'&&d[i+1]=='L'&&d[i+2]=='E')
main() {
{ strcat(sd,"DLEDLE");
char s[]="DLESTX",d[10]="",sd[10]="",j; i+=3;
int i=0;j=0; j+=6;
printf("ENTER THE MSG"); }
scanf("%s",&d); sd[j]=d[i];
if(strlen(d)<3) j++;
{ i++;
}
strcat(sd,d); strcat(s,sd);
strcat(sd,"DLEETX"); strcat(s,"DLEETX");
printf("The stuffed data is %s",sd); printf("Message after stuffing is %s",s);
} }
}
else
{
while(d[j]!= '\0')
{
BIT STUFFING
• In a data link frame, the delimiting flag sequence
generally contains six or more consecutive 1s.
• In order to differentiate the message from the flag in
case of the same sequence, a single bit is stuffed in the
message.
• Whenever a 0 bit is followed by five consecutive 1bits
in the message, an extra 0 bit is stuffed at the end of
the five 1s.
• When the receiver receives the message, it removes the
stuffed 0s after each sequence of five 1s. The un-stuffed
message is then sent to the upper layers.
Algorithm for Bit−Stuffing
1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110
which indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 0111 1110
at the end
6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed
bits
7. Display the received bit stream
8. Stop
BIT STUFFING
#include<stdio.h> if(count==5)
#include<string.h> {
void main() j++;
{ b[j]=0;
int a[20],b[30],i,j,k,count,n; }
printf("Enter frame length:"); i=k;
scanf("%d",&n); }
printf("Enter input frame (0's & 1's only):"); }
for(i=0;i<n;i++) else
scanf("%d",&a[i]); {
i=0; count=1; j=0; b[j]=a[i];
while(i<n) }
{ i++;
if(a[i]==1) j++;
{ }
b[j]=a[i]; printf("After stuffing the frame is:");
for(k=i+1;a[k]==1 && k<n && count<5;k++) for(i=0;i<j;i++)
{ printf("%d",b[i]);
j++; }
b[j]=a[k];
count++;

You might also like