Bit Stuffing

C Program

#include <stdio.h>
#include <string.h>

int main() {
    int n;
    printf("Enter the number of bits: ");
    scanf("%d", &n);

    char bits[n+1];
    printf("Enter the bits: ");
    scanf("%s", bits);

    int count = 0;
    int zeroFound = 0;
    for (int i = 0; i < strlen(bits); i++) {
        if (bits[i] == '1') {
            count++;
            if (count == 5 && zeroFound) {
                printf("111110");
                count = 0;
            }
        } else {
            for (int j = 0; j < count; j++) {
                printf("1");
            }
            printf("0");
            count = 0;
            zeroFound = 1;
        }
    }
    for (int j = 0; j < count; j++) {
        printf("1");
    }
    if(zeroFound){
        printf("\nstuffed!!\n");
    }else{
        printf("\nno need to stuff!!\n");
    }

    return 0;
}

Output

output of bit stuffing c program
output of bit stuffing c program

Related Posts

Artificial Intelligence Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Artificial Intelligence Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Mixed Signal Design Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Mixed Signal Design Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Fiber Optic Communication Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Fiber Optic Communication Suggestions! Elevate Your Learning Experience and Excel with Confidence.

Cyber Security Suggestions

Unlock Success in Your MAKAUT Semester Exam with These Empowering Cyber Security Suggestions! Elevate Your Learning Experience and Excel with Confidence.

MAKAUT 7th Semester Examination Questions – 2023

Mobile Communication and Networks (PE-EC701C) Neural Network and Fuzzy Logic Control (PE-EC702C/PEROB701B) Principles of Management (HS-HU701)

CSS Cheatsheet

Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…

Leave a Reply

Your email address will not be published. Required fields are marked *