Bit Stuffing: Kush Dept. of Cse
Bit Stuffing: Kush Dept. of Cse
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
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");
}
}
}