Home / C / C Program for Bit Stuffing

C Program for Bit Stuffing

Bit Stuffing: In bit stuffing following rules hold:- 

  1. To the given bits add the string 01111110 to both the starting and the end of the string
  2. To add 0 to each set of 5 one’s i.e. after every five consecutive 1’s appear a zero
#include "stdio.h"
#include "conio.h"
int main()
{
int i=0,count=0;
char a[100];
printf("enter the bits : ");
scanf("%s",a);

printf("\nAfter bit stuffing \n");
printf("01111110");

for(i=0;a[i]; i++)
{
    if(a[i]=='1')
        count++;
    else
        count=0;
printf("%c",a[i]);
if(count==5)
    {
        printf("0");
        count=0;
    }
}
printf("01111110");
getch();
return 1;
}

 

OUTPUT:

bit stuffing

 

Tags: Write a C program for bit stuffing, bit-stuffing

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

7 comments

  1. program is not correctly executing

  2. cout1 is not initilized

  3. awesome code…. and its soooooooooooo simple and short….. thank you

  4. very useful….
    but the coding for destuffing the bits is not found..

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.