0% found this document useful (0 votes)
121 views4 pages

Bit and Character Stuffing in C

This document describes programs that demonstrate bit stuffing and character stuffing. Bit stuffing inserts a 0 bit after every sequence of 5 consecutive 1 bits in the frame. Character stuffing inserts special characters like "dle" before and after a special character to be transmitted. The character stuffing program takes a string as input, inserts stuffing characters at a specified position, and before and after occurrences of the string "dle". Both programs transmit the stuffed frame and illustrate the concepts of bit and character stuffing.

Uploaded by

poojan thakkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views4 pages

Bit and Character Stuffing in C

This document describes programs that demonstrate bit stuffing and character stuffing. Bit stuffing inserts a 0 bit after every sequence of 5 consecutive 1 bits in the frame. Character stuffing inserts special characters like "dle" before and after a special character to be transmitted. The character stuffing program takes a string as input, inserts stuffing characters at a specified position, and before and after occurrences of the string "dle". Both programs transmit the stuffed frame and illustrate the concepts of bit and character stuffing.

Uploaded by

poojan thakkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PRACTICAL-8

Aim : Write a program which demonstrates the concept of bit stuffing and
character stuffing.

Hardware Requirement :- Computer or Laptop for run program

Software Requirement:- Turbo c++

Knowledge Requirment :- knowledge require about c programming and concept of bit


stuffing and character stuffing.

 Bit Stuffing Program :

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int a[20],b[30],i,j,k,count,n;
    printf("Enter frame size (Example: 8):");
    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++)
            {
                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]);
    getch();
}

 Character Stuffing Program :

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
int _tmain(int argc, _TCHAR* argv[])
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("Enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("\nEnter position : ");
scanf("%d",&pos);
if(pos>n)
{
printf("Invalid position, Enter again : ");
scanf("%d",&pos);
}
printf("Enter the character: ");
ch=getche();

b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}

b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\n\nFrame after stuffing: ");
printf("%s",b);
getch();
return 0;
}
 Questions and Answers
1. What is Byte Stuffing ?
 In this method, start and end of frame are recognized with the help of flag bytes.
Each frames starts with and ends with a flag byte. Two consecutive flag bytes
indicate the end of one frame and start of the next one.

 Conclusion
 In this Practical we know the concept of Bit stuffing and character stuffing
through the program.

You might also like