//------ topic 5.1 ------
void mergeTwo(int n,int m, int i,int j){
	m = m << i;
	n = n >> j;
	n = n << j;
	n = n | m;
	std::cout<<dec2binary(n)<<std::endl;
}
示例#2
0
文件: a.c 项目: anirudd/dsp_lab
void main()
{
FILE *fp,*fp1,*fp2, *fp4,*fp5;
fp=fopen("ai.txt","r");
fp1=fopen("8bit.txt","w");
fp2=fopen("compressed.txt","w");
fp4=fopen("7bit.txt","w");
fp5=fopen("temp.txt","w");
char a;
unsigned int b;
int rep[8];
int i,ii=0;
char in[3];
while((a=fgetc(fp))!=EOF)
{
ii=0;
while(a!='\n')
{
in[ii]=a;
ii++;
a=fgetc(fp);
}
ii--;
b=0;
for(i=0;i<=ii;i++)
{
int l=ii-i;
int ll=(int)in[i]-48;
b+=pow(10,l)*ll;
}


dec2binary(b,rep);

int quo,quo1;
for(i=0;i<8;i++)
{
if(rep[i]==0)
quo=48;
else
quo=49;
fputc(quo,fp1);
if(i!=7)
{
fputc(quo,fp4);
fputc(quo,fp5);
}

}


}
fseek(fp5,0,SEEK_END);
int sz=ftell(fp5);
if((sz%8)!=0)
{
int yy=sz%8;
char p='0';
int pp=(int)p;
for(i=1;i<=yy;i++)
{
fputc(pp,fp5);
}
}

fclose(fp);
fclose(fp1);
fclose(fp4);
fclose(fp5);

FILE *fp3;
fp3=fopen("temp.txt","r");
fseek(fp3,0,SEEK_END);
int sz1=ftell(fp3);
sz1=sz1/8;
fseek(fp3,0,SEEK_SET);
int qq;
char ip[8];
for(i=0;i<sz1;i++)
{
int qq=0;
for(qq=0;qq<8;qq++)
{
ip[qq]=fgetc(fp3);
}
int res=bin2dec(ip);
fputc(res,fp2);
}

fclose(fp2);
fclose(fp3);
}
示例#3
0
文件: dsplab1.c 项目: anirudd/dsp_lab
void main()
{
FILE *fp,*fp1,*fp2,*fp3,*fp4,*fp5;
fp=fopen("abc_cmprsd.wav","r");
fp1=fopen("abc_dcmprsd.wav","w");
fp2=fopen("tempo.txt","w");
fp3=fopen("tempo1.txt","w");
fseek(fp,0,SEEK_END);
int cntrl=0,l=0;
unsigned long long int len=ftell(fp);
printf("%lu",len);
fseek(fp,0,SEEK_SET);
unsigned int a;
char ch;
int rep[8],i=0,quo,j=0;
while(ftell(fp)<len)
{
while(ftell(fp)<44)
{
a=fgetc(fp);
fputc(a,fp1);
}



//printf("\n%lu",ftell(fp));
a=fgetc(fp);
dec2binary(a,rep);
if(cntrl==0)
{
for(i=0;i<7-l;i++)
{
if(rep[i]==0)
quo=48;
else
quo=49;
fputc(quo,fp2);
}
fputc(48,fp2);
for(i=7-l;i<8;i++)
{
if(rep[i]==0)
quo=48;
else
quo=49;
fputc(quo,fp2);
}
if(l==7)
{
cntrl=0;
l=0;
}
else
{
cntrl=1;
l++;
}
}
else
{
for(i=0;i<8;i++)
{
if(rep[i]==0)
quo=48;
else
quo=49;
fputc(quo,fp2);
}
cntrl=0;
}

}
printf("\n%lu",ftell(fp));
fclose(fp2);
fp5=fopen("tempo.txt","r");
fseek(fp5,0,SEEK_END);
unsigned long long int len1=ftell(fp5);
printf("\n%llu",len1);
int len2=len1%8;
len1=len1-len2;
fseek(fp5,0,SEEK_SET);
while(ftell(fp5)<len1)
{
a=fgetc(fp2);
fputc(a,fp3);
}
fclose(fp);
fclose(fp5);
fclose(fp3);
fp4=fopen("tempo1.txt","r");
fseek(fp4,0,SEEK_END);
unsigned long int len3=ftell(fp4);
fseek(fp4,0,SEEK_SET);
len3=len3/8;
for(i=0;i<len3;i++)
{
for(j=0;j<8;j++)
{
rep[j]=fgetc(fp4)-48;
}
a=bin2dec(rep);
fputc(a,fp1);
}
fclose(fp4);
fclose(fp1);
}