0% found this document useful (0 votes)
38 views

Bit Stuffing: Kush Dept. of Cse

Bit stuffing is a technique used to ensure reliable data transmission over communication channels. It involves inserting extra bits into the data transmitted to guarantee that special bit patterns only occur at frame boundaries. The algorithm works as follows: 1. Whenever 5 consecutive 1 bits are encountered in the data, a 0 bit is stuffed into the outgoing bit stream. 2. At the receiver, whenever 5 consecutive 1 bits followed by a 0 bit are seen, the 0 bit is removed. 3. This allows the special frame boundary patterns to be unambiguously recognized despite bit stuffing and destuffing occurring in the data.

Uploaded by

deepak sureddi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Bit Stuffing: Kush Dept. of Cse

Bit stuffing is a technique used to ensure reliable data transmission over communication channels. It involves inserting extra bits into the data transmitted to guarantee that special bit patterns only occur at frame boundaries. The algorithm works as follows: 1. Whenever 5 consecutive 1 bits are encountered in the data, a 0 bit is stuffed into the outgoing bit stream. 2. At the receiver, whenever 5 consecutive 1 bits followed by a 0 bit are seen, the 0 bit is removed. 3. This allows the special frame boundary patterns to be unambiguously recognized despite bit stuffing and destuffing occurring in the data.

Uploaded by

deepak sureddi
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

KUSH

DEPT. OF CSE
Date:

Exp No: 1

BIT STUFFING
AIM: Program to implement the technique of bit stuffing.
DESCRIPTION:
Generally every frame begins and ends with a special bit pattern
such as 010111010.Considering also the flag byte. Whenever the sender
data link layers encounter 5 consecutive in the data the compiler
automatically stuffs a 0 bit on to the outgoing bit stream. Whenever the
receiver sees consecutive incoming 1 bit followed by a 0 bit, it
automatically destroys the 0 bit. In this pattern of can be unambiguously
recognized by the flag pattern. So if the receiver losses the track by input
for their sequence. Since they can only occur at frame boundaries and
never with data.
ALGORITHM:
Step 1: read the data
Step 2: initialize count to zero.
Step 3: if i>n then go to step 10
Step 4: if count is not equal to 5 then go to step 6
Step 5: right shift the bits from i to last
Step 6: if a[i] is not equal to 1 ten go to step 8
Step 7: increment the counter, go to step 9
Step 8: count=0
Step 9: go to step 3
Step 10: print the stuffed message
Step 11: if i>n then go to step 18
Step 12: if count not equal to 6 then go to step 14
Step 13: left shift the bits

KUSH
DEPT. OF CSE
Date:

Exp No: 1

Step 14: if a[i] not equal to 1 then go to step 16


Step 15: increment the counter go to step 17
Step 16: count=0
Step 17: go to step 11
Step 18: print the destuffed message
Step 19: stop

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
clrscr();
while(1)
{
char s[20],a[20];
int i,j,k,u,l,ch,count=0;
printf("\n1.stuff\n2.destuff\n3.exit");
printf("\nenter choice");
scanf("%d",&ch);
switch(ch)
{
case 1:l=0,i=0,j=0;
printf("enter string");

KUSH
DEPT. OF CSE
Date:

Exp No: 1
scanf("%s",&s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='1')
{
a[j++]=s[i];
count++;
}
else
{
a[j++]=s[i];
count=0;
}
if(count==5)
{
a[j++]='0';
count=0;
}
}
a[j]='\0';
printf("%s",a);
break;
3

KUSH
DEPT. OF CSE
Date:

Exp No: 1
case 2:
count=0;j=0;l=0;i=0;
printf("\nenter stuffed string");
scanf("%s",&s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='1')
{
a[j++]=s[i];
count++;
}
else
{
a[j++]=s[i];
count=0;
}
if(count==5)
{
count=0;
i=i+1;
}
}
4

KUSH
DEPT. OF CSE
Date:

Exp No: 1
a[j]='\0';
printf("%s",a);
break;
case 3:return;
default:printf("w");
}
}
}

You might also like