You are on page 1of 3

LAB CYCLE-1 Date:01-02-13

PROGRAM -1

AIM: Write a c program to implement bit stuffing

DESCRIPTION :

Bit stuffing is the insertion of one or more bits into a transmission unit as a way to provide
signaling information to a receiver. The receiver knows how to detect and remove or disregard the
stuffed bits. Bit stuffing is defined by some to include bit padding, which is the addition of bits to a
transmission to make the transmission unit conform to a standard size.

ALGORITHM:

1.Read the number of frames.


2. Read the binary data for each frame.
3. Add the flag.
4. Bit Stuffing: If there is five consecutive 1’s after zero ,add one zero as sixth bit.
5. Transmit the data.
6. Destuffing: If there is zero after the five consecutive 1’s, remove that zero in the data.
7. Display the data.

Fig-1. Bit stuffing. (a) The original data. (b) The data as they appear on the line. (c) The data as they are stored in
the receiver's memory after destuffing.

ADVANTAGES AND DISADVANTAGES:

a. boundary between two frames are clearly recognized


b. error correction is made easier
c. waste of bandwidth
d. computing time needed to insert and remove the bit stuffing

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 20
int main(int argc, char *argv[])
{
char a[max],f[8]={'0','1','1','1','1','1','1','0'};
int count=0,i=0,j,l,k=0;

Dept of CSE, K L UNIVERSITY 1 Reg no-12203008


LAB CYCLE-1 Date:01-02-13

printf("\nEnter the input string");


scanf("%s",a);
printf("\nthe flag is: ");
for(i=0;i<8;i++)
printf("%c",f[i]);
l=strlen(a);
for(i=0;i<l;i++)
if(a[i]=='1')
{
k=i;
count=0;
while(a[k]=='1')
{
count+=1;
k++;
if(count==5)
{
for(j=l+1;j>k;j--)
{
a[j]=a[j-1];
}
a[k]='0';
l++;
break;
}
i=k;
}
}
printf("\n The bitstuffed string is %s",a);
k=0;
for(i=0;i<=l;i++)
{
if(a[i]=='1')
{
k=i;
count=0;
while(a[k]=='1')
{
count+=1;
k++;
if(count==5)
{
for(j=k;j<l+1;j++)
{
a[j]=a[j+1];
}
l--;
a[l+1]='0';
break;
}
}

Dept of CSE, K L UNIVERSITY 2 Reg no-12203008


LAB CYCLE-1 Date:01-02-13

i=k-1;
}
}
printf("\nString after unstuffing %s\n",a);
return 0;
}

OUTPUT 1:

Enter the input string1111111011


the flag is: 01111110
The bitstuffed string is 11111011011
String after unstuffing 1111111011

OUTPUT 2:

Enter the input string10101111110010


the flag is: 01111110
The bitstuffed string is 101011111010010
String after unstuffing 10101111110010

Dept of CSE, K L UNIVERSITY 3 Reg no-12203008

You might also like