Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
53 views3 pages

Bit Stuffing and Destuffing

Uploaded by

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

Bit Stuffing and Destuffing

Uploaded by

mattmck0813
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Bit Stuffing and Destuffing

C language code: -
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *p,*q;
char temp;
char in[100];
char stuff[100];
char destuff[100];
int count=0;
printf("enter the input character string (0‘s & 1‘s only):\n");
scanf("%s",in);
p=in;
q=stuff;
while(*p!='\0')
{
if(*p=='0')
{
while(*p=='0' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='1';
q++;
}
count=0;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='0';
q++;
}
count=0;
}
}
*q='\0';
printf("\nafter bit stuffing is:");
printf("\n%s",stuff);
p=stuff;
q=destuff;
while(*p!='\0')
{
if(*p=='0')
{
while(*p=='0' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nAfter bit destuffing is:");
printf("\n%s\n",destuff);
return 0;
}

You might also like