Bit stuffing program in C
In this post, you will learn about the bit stuffing using the C programming language.
Bit stuffing refers to the insertion of one or more bits into a data transmission as a way to provide signaling information to a receiver.
In the OSI model, the size of the data frames in variable-length frames may vary. In such cases, it's very difficult to detect the end and beginning of a frame. Hence, bit stuffing is used to mark the end and beginning of the frames during variable-length data frame transfer.
Bit stuffing is a process of inserting an extra bit as 0, once the frame sequence encountered 5 consecutive 1's. In the given source code of C programming in bit stuffing, while loop is used.
#include<stdio.h>
#include<string.h>
int main()
{
int x[20],y[30],i,j,k,count,n;
printf("Enter frame size: ");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1: ");
for(i=0; i<n; i++)
scanf("%d",&x[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(x[i]==1)
{
y[j]=x[i];
for(k=i+1; x[k]==1 && k<5; k++)
{
j++;
y[j]=x[k];
count++;
if(count==5)
{
j++;
y[j]=0;
}
i=k;
}
}
else
{
y[j]=x[i];
}
i++;
j++;
}
printf("After Bit Stuffing: ");
for(i=0; i<j; i++)
printf("%d",y[i]);
return 0;
}
Output of the above code:
Enter frame size: 12
Enter the frame in the form of 0 and 1 : 1 1 1 0 1 1 1 1 0 1 1 1
After Bit Stuffing : 1110111010111
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
C program to convert celsius to fahrenheit
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative