bit stuffing

PHOTO EMBED

Thu Nov 07 2024 17:29:07 GMT+0000 (Coordinated Universal Time)

Saved by @freefire

#include<stdio.h> 
#include<string.h> 
int main() 
{ 
int a[20],b[30],i,j,k,count,n; 
printf("Enter frame size (Example: 8):"); 
scanf("%d",&n); 
printf("Enter the frame in the form of 0 and 1 :"); 
    for(i=0; i<n; i++) 
        scanf("%d",&a[i]); 
    i=0; 
    count=1; 
    j=0; 
    while(i<n) 
    { 
        if(a[i]==1) 
        { 
            b[j]=a[i]; 
            for(k=i+1; a[k]==1 && k<n && count<5; k++) 
            { 
                j++; 
                b[j]=a[k]; 
                count++; 
                if(count==5) 
                { 
                    j++; 
                    b[j]=0; 
                } 
                i=k; 
            } 
        } 
        else 
        { 
            b[j]=a[i]; 
        } 
i++; 
j++; 
} 
printf("After Bit Stuffing :"); 
for(i=0; i<j; i++) 
printf("%d",b[i]); 
return 0; 
} 
Output: Enter frame size (Example: 8):12 
Enter the frame in the form of 0 and 1 :0 1 0 1 1 1 1 1 1 0 0 1 
After Bit Stuffing :0101111101001 
content_copyCOPY