Program to implement Bit Stuffing
1. BitStuffing:
#include<stdio.h> #include<conio.h> void main() { char a[10]; int count=0, i=0, j, l, k=0; clrscr(); printf("Enter the input string"); scanf("%s", a); l = strlen(a); for(i=0; i < l; i++) if(a[i] == '1') { k = i; count = 0; while(a[k] == '1') { count += 1; k++; if(count == 5) { for(j = l + 1; j > k; j--) { a[j] = a[j - 1]; } a[k] = '0'; l++; break; } i = k; } } printf("\n The bitstuffed string is %s", a); getch(); k = 0; for(i = 0; i <= l; i++) { if(a[i] == '1') { k = i; count = 0; while(a[k] == '1') { count++ = 1; k ; if(count == 5) { for(j = k; j < l + 1; j++) { a[j] = a[j + 1]; } l--; a[l + 1] = '0'; break; } } i = k - 1; } } printf("String after unstuffing %s\n", a); getch(); }
Output:
Enter bit string:1011111011110111110
After stuffing:0111111010111110011110111110001111110
-
UpdatedNov 05, 2014
-
Views11,341