225k views
2 votes
Program for bit stuffing...?

User JATothrim
by
6.3k points

1 Answer

2 votes

Answer: Program for bit stuffing in C

#include<stdio.h>

int main()

{

int i=0,count=0;

char data[50];

printf("Enter the Bits: ");

scanf("%s",data); //entering the bits ie. 0,1

printf("Data Bits Before Bit Stuffing:%s",databits);

printf("\\Data Bits After Bit stuffing :");

for(i=0; i<strlen(data); i++)

{

if(data[i]=='1')

count++;

else

count=0;

printf("%c",data[i]);

if(count==4)

{

printf("0");

count=0;

}

}

return 0;

}

Step-by-step explanation:

bit stuffing is the insertion of non-information bits during transmission of frames between sender and receiver. In the above program we are stuffing 0 bit after 4 consecutive 1's. So to count the number of 1's we have used a count variable. We have used a char array to store the data bits . We use a for loop to iterate through the data bits to stuff a 0 after 4 consecutive 1's.

User Moema
by
5.2k points