Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- void main()
- {
- int a[70],i,j,n,count=0,l;
- char b[20],c[20];
- printf("enter bit length to be stuffed:");
- scanf("%d",&n);
- printf("enter string");
- for(i=0;i<n;i++)
- {
- scanf("%d",&a[i]);
- }
- i=0;
- for(j=0;j<n;j++)
- {
- if(a[j]==1)
- count++;
- if(count==5)
- {
- b[i++]=a[j]+'0';
- b[i++]=0+'0';
- count=0;
- }
- else
- {
- b[i++]=a[j]+'0';
- }
- }
- printf("\n stuffed string:%s",b);
- j=0;
- n=strlen(b);
- count=0;
- for(i=0;i<n;i++)
- {
- if(b[i]=='1')
- {
- count++;
- }
- if(count==5)
- {
- c[j++]=b[i];
- i=i+1;
- count=0;
- }
- else
- c[j++]=b[i];
- }
- c[j]='\0';
- printf("\n destuffed string %s",c);
- }
- OUTPUT
- [12311A1256@itlab cn]$ cc bitstuffing.c
- [12311A1256@itlab cn]$ ./a.out
- enter bit length to be stuffed:10
- enter string1
- 0
- 0
- 0
- 1
- 1
- 0
- 1
- 0
- 1
- stuffed string:10001101010
- destuffed string 1000110101
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement