C Program for Bit Stuffing

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
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 stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}

OUTPUT:

Enter frame length: 10

Enter input frame (0′s & 1′s only):
 1 0 1 0 1 1 1 1 1 1

After stuffing the frame is:
 1 0 1 0 1 1 1 1 1 0 1



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C Program – Character stuffing
  2. c program to swap the contents of two numbers using bit-wise XOR operation. Don’t use either the temporary variable or arithmetic operators
  3. C Program to convert the lower case letters to upper case and vice-versa
  4. C program – Round Robin CPU Scheduling Algorithm
  5. C program to generate and print first N FIBONACCI numbers

Leave a Comment

Previous post:

Next post: