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

Bit Stuffing: Experiment No.:-Date: - Aim: - Write A Program To Perform A Bit Stuffing Using RS-232. Program

The document describes a program to perform bit stuffing using RS-232. Bit stuffing is a technique used to ensure sufficient transition density when transmitting serial data. The program allows the user to choose between sending data, receiving data, or exiting. It stuffs bits by inserting additional 0 bits after sequences of 5 consecutive 1 bits in the data. When receiving, it removes the stuffed bits by looking for sequences of 7 consecutive 1 bits followed by a 0.

Uploaded by

Hardik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views4 pages

Bit Stuffing: Experiment No.:-Date: - Aim: - Write A Program To Perform A Bit Stuffing Using RS-232. Program

The document describes a program to perform bit stuffing using RS-232. Bit stuffing is a technique used to ensure sufficient transition density when transmitting serial data. The program allows the user to choose between sending data, receiving data, or exiting. It stuffs bits by inserting additional 0 bits after sequences of 5 consecutive 1 bits in the data. When receiving, it removes the stuffed bits by looking for sequences of 7 consecutive 1 bits followed by a 0.

Uploaded by

Hardik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Bit Stuffing

Experiment No.:- Date:-

Aim:- Write a program to perform a bit stuffing using RS-232.

Program:-

#include<bios.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
clrscr();
int n,i,j,k,status,count=0,l;
char vs[50],vr[50],s[50]="01111110",d[50];
bioscom(0,0xeb,0);
printf("\n1:Sending\n2:Receving\n3:Exit\n Your Choice:-");
scanf("%d",&n);
strcpy(d,s);
switch(n)
{
case 1:printf("\nEnter data:-"); //Sending Data
scanf("%s",&vs);
l=strlen(vs);
j=8;
for(i=0;i<l;i++)
{
s[j]=vs[i];
if(vs[i]=='1')
{
count++;
if(count==5)
{
j++;
s[j]='0';
count=0;
}
}
else
count=0;
j++;
}
strcat(s,d);
printf("\nStuffed Data:-%s",s);
l=strlen(s);
for(i=0;i<=l;i++)
outport(0x3f8,s[i]);
break;
case 2:i=0; //Receiving Data
do
{
status=bioscom(3,0,0);
if(status & 0x100)
{
vr[i]=inport(0x3f8);
if(vr[i]=='\0')
goto f;
i++;
}
}while(1);
f:printf("Stuffed Data:-%s",vr);
k=strlen(vr);
j=0;
for(i=8;i<k;i++)
{
if(vr[i]=='0' && vr[i+1]=='1' && vr[i+2]=='1' && vr[i+3]=='1' &&
vr[i+4]=='1' && vr[i+5]=='1' && vr[i+6]=='1' && vr[i+7]=='0')
{
goto e;
}
s[j]=vr[i];
if(vr[i]=='1')
{
count++;
if(count==5)
{
i++;
count=0;
}
}
else
count=0;
j++;
}
e:s[j]='\0';
printf("\nData:-%s",s);
break;
case 3:exit(0); //Exit
default:break;
}
getch();
}
Flow Chart:-

You might also like