You are on page 1of 4

1a) Implement the data link layer framing bit stuffing method.

#include<stdio.h>
#include<conio.h>
void main()
{
int x=0,j=0,l,k=0,c=0,i,n,A[50],B[50],C[50];
clrscr();
printf("\nEnter the no. of bits-");
scanf("%d",&n);
l=n;
printf("\nEnter the bits [and press enter after every bit]-\n");
for(i=0;i<n;i++)
{
printf("\nEnter the bit-");
scanf("%d",&A[i]);
}
printf("\nEntered bits are-\n");
for(i=0;i<n;i++)
printf("%d",A[i]);
printf("\n***SENDER***\n");
for(i=0;i<n;i++)
{
if(A[i]==0)
{
B[k]=0;

k++;
c=0;
}
else
{
B[k]=1;
k++;
c++;
}
if(c==5)
{
B[k]=0;
k++;
c=0;
l++;
}
}
for(i=0;i<l;i++)
printf("%d",B[i]);
printf("\n***RECIEVER***\n");
for(i=0;i<l;i++)
{
if(x==5)
{
x=0;
}

else
{
if(B[i]==0)
{
C[j]=0;
j++;
x=0;
}
else
{
x++;
C[j]=1;
j++;
}
}
}

for(i=0;i<n;i++)
printf("%d",C[i]);
getch();
}

OUTPUT:

Enter no.of bits 10


Enter the bit [ and press enter after every bit]-

Enter the bit - 1


Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 1
Enter the bit - 0
Enter the bit 0
Entered bits are
1111111100
*****SENDER*****
11111011100
*****RECEIVER*****
1111111100

You might also like