0% found this document useful (0 votes)
30 views7 pages

Computer Networks

This document contains code to implement bit stuffing and byte stuffing. For bit stuffing, it takes in a binary frame as input, inserts 0s whenever there are 5 consecutive 1s, and outputs the stuffed frame. For byte stuffing, it takes in a string frame, inserts "esc" before strings that equal "flag" or "esc", and outputs the stuffed frame. The aim was to compile and execute these implementations, which was successful as per the results.

Uploaded by

Aeydap
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
30 views7 pages

Computer Networks

This document contains code to implement bit stuffing and byte stuffing. For bit stuffing, it takes in a binary frame as input, inserts 0s whenever there are 5 consecutive 1s, and outputs the stuffed frame. For byte stuffing, it takes in a string frame, inserts "esc" before strings that equal "flag" or "esc", and outputs the stuffed frame. The aim was to compile and execute these implementations, which was successful as per the results.

Uploaded by

Aeydap
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

ROLL NO.

: 18CSR028

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
Ex.No. 4 PROGRAM TO IMPLEMENT BIT AND BYTE STUFFING
:
Date : 3/12/20
20

Aim :

To compile and execute the implementation of bit and byte stuffing

Coding :

BIT STUFFING

#include<stdio.h>

#include<string.h>

int main()

int a[20],b[30],i,j,k,count,n;

printf("Enter frame size :");

scanf("%d",&n);

printf("Enter the frame in the form of 0 and 1 :");

for(i=0; i<n; i++)

scanf("%d",&a[i]);

i=0;

count=1;

j=0;

while(i<n)

if(a[i]==1)

b[j]=a[i];

for(k=i+1; a[k]==1 && k<n && count<5; k++)

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
{

j++;

b[j]=a[k];

count++;

if(count==5)

j++;

b[j]=0;

i=k;

else

b[j]=a[i];

i++;

j++;

printf("After Bit Stuffing :");

for(i=0; i<j; i++)

printf("%d",b[i]);

return 0;

BYTE STUFFING

#include<stdio.h>

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
#include<string.h>

void main(){

char frame[50][50],str[50][50];

char flag[10];

strcpy(flag,"flag");

char esc[10];

strcpy(esc,"esc");

int i,j,k=0,n;

strcpy(frame[k++],"flag");

printf("Enter no.of String :\t");

scanf("%d",&n);

printf("Enter String \n");

for(i=0;i<=n;i++)

gets(str[i]);

printf("You entered :\n");

for(i=0;i<=n;i++)

puts(str[i]);

printf("\n");

for(i=1;i<=n;i++)

if(strcmp(str[i],flag)!=0 && strcmp(str[i],esc)!=0)

strcpy(frame[k++],str[i]);

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028
}

else

strcpy(frame[k++],"esc");

strcpy(frame[k++],str[i]);

strcpy(frame[k++],"flag");

//frame[k++]='\0';

printf("------------------------------\n");

printf("Byte stuffing at sender side:\n\n");

printf("------------------------------\n");

for(i=0;i<k;i++)

printf("%s\t",frame[i]);

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028

Sample I/O:

Screenshot

BIT STUFFING

BYTE STUFFING

CN LAB /2020-21/ODD/A SECTION


ROLL NO.: 18CSR028

Result:

The implementation of bit and byte stuffing has been successfully compiled
and executed

CN LAB /2020-21/ODD/A SECTION

You might also like