BIT STUFFING
Fri Nov 15 2024 17:51:43 GMT+0000 (Coordinated Universal Time)
Saved by
@coding1
#include<stdio.h>
#include<string.h>
void bitStuffing(char *str) {
int i, count = 0;
char stuffedStr[100] = ""; // initialize an empty string to store the stuffed bits
for (i = 0; i < strlen(str); i++) {
if (str[i] == '1') {
count++;
if (count == 5) {
strcat(stuffedStr, "0"); // stuff a '0' bit
count = 0;
}
} else {
count = 0;
}
char temp[2];
sprintf(temp, "%c", str[i]);
strcat(stuffedStr, temp);
}
printf("Original string: %s\n", str);
printf("Bit-stuffed string: %s\n", stuffedStr);
}
int main() {
char str[100];
printf("Enter a binary string: ");
scanf("%s", str);
bitStuffing(str);
return 0;
}
content_copyCOPY
Comments