Source Code

Get programs to develop you own applications.

Bit Stuffing in C

Posted by mohammedmoulana on April 3, 2012

Bitstopfen Bit stuffing

Bitstopfen Bit stuffing (Photo credit: Wikipedia)

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.

Zero-bit insertion is a particular type of bit stuffing (in the latter sense) used in some data transmission protocols.

/*Implement the DataLinklayer framing methods such as Bit stuffing*/
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
int main()
{
char *p,*q;
char temp;
char in[MAXSIZE];
char stuff[MAXSIZE];
char destuff[MAXSIZE];
int count=0;
printf(“enter the input character string\n”);
scanf(“%s”,in);
p=in;
q=stuff;
while(*p!=”)
{
if(*p==’0′)
{
*q=*p;
q++;
p++;
}
else
{
while(*p==’1′ && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q=’0′;
q++;
}
count=0;
}
}
*q=”;
printf(“\nthe stuffed character string is”);
printf(“\n%s”,stuff);
p=stuff;
q=destuff;
while(*p!=”)
{
if(*p==’0′)
{
*q=*p;
q++;
p++;
}
else
{
while(*p==’1′ && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
}
*q=”;
printf(“\nthe destuffed character string is”);
printf(“\n%s\n”,destuff);
return 0;
}

\n

About these ads

One Response to “Bit Stuffing in C”

  1. [...] Bit Stuffing in C (sourcecode4all.wordpress.com) Rate this: Share this:Like this:LikeOne blogger likes this post. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 442 other followers

%d bloggers like this: