Advertisement
WarPro

bitstuff

Nov 24th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. void main()
  4. {
  5. int a[70],i,j,n,count=0,l;
  6. char b[20],c[20];
  7. printf("enter bit length to be stuffed:");
  8. scanf("%d",&n);
  9. printf("enter string");
  10. for(i=0;i<n;i++)
  11. {
  12. scanf("%d",&a[i]);
  13. }
  14. i=0;
  15. for(j=0;j<n;j++)
  16. {
  17. if(a[j]==1)
  18. count++;
  19. if(count==5)
  20. {
  21. b[i++]=a[j]+'0';
  22. b[i++]=0+'0';
  23. count=0;
  24. }
  25. else
  26. {
  27. b[i++]=a[j]+'0';
  28. }
  29. }
  30. printf("\n stuffed string:%s",b);
  31. j=0;
  32. n=strlen(b);
  33. count=0;
  34. for(i=0;i<n;i++)
  35. {
  36. if(b[i]=='1')
  37. {
  38. count++;
  39. }
  40. if(count==5)
  41. {
  42. c[j++]=b[i];
  43. i=i+1;
  44. count=0;
  45. }
  46. else
  47. c[j++]=b[i];
  48. }
  49. c[j]='\0';
  50. printf("\n destuffed string %s",c);
  51. }
  52.  
  53. OUTPUT
  54.  
  55. [12311A1256@itlab cn]$ cc bitstuffing.c
  56. [12311A1256@itlab cn]$ ./a.out
  57. enter bit length to be stuffed:10
  58. enter string1
  59. 0
  60. 0
  61. 0
  62. 1
  63. 1
  64. 0
  65. 1
  66. 0
  67. 1
  68.  
  69. stuffed string:10001101010
  70. destuffed string 1000110101
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement