/*****************************************************************
This program adds zeros to the
required positions given by user (i.e Zero-bit insertion at multiple position)
******************************************************************/
/* MULTIPLE BIT STUFFING */
#include<stdio.h>
#define arr 15
int main(){
// variable declaration
int i,n,count=1,j,k,t;
int a[arr],b[arr],m[arr];
// user input
printf("Enter No of Bits : ");
scanf("%d",&n);
printf("Enter Number(I/P) in binary : ");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
// Multiple bit stuffing
printf("\nAt how many positions U want to add ZERO : ");
scanf("%d",&t);
printf("Enter positions where U want to add a ZERO : ");
for(k=0;k<t;k++)
scanf("%d",&m[k]);
for(i=0,j=0,k=0;i<n,j<(n+t);i++,j++){
if(count==m[k]){
b[j]=0; // adding extra bit '0'
i--;
k++;
}
else
b[j]=a[i];
count++;
}
// ERROR checking
for(i=0;i<n;i++)
{
if(a[i]!=b[i])
{
printf("Error position = %d \n",i+1);
}
}
// Displaying output
printf("\n\nThe resultant no(O/P) is : ");
for(j=0;j<(n+t);j++){
printf("%d",b[j]);
}
printf("\n");
return 0;
}
No comments:
Post a Comment