資源簡介
算數編碼編解碼C++程序 親自測試可用 供學習使用
代碼片段和文件信息
#include
#include“math.h“
char?S[100]?A[10];
float??P[10]f[10]gFs;
void?bianma(int?aint?h)
{
int?ij;
float?fr;
float?ps=1;
float?Fs=0;
float?Sp[100]b[100]F[100];
for(i=0;i {
for(j=0;j {
if(S[i]==A[j])
{
Sp[i]=P[j];
fr=f[j];
}
}
Fs=Fs+ps*fr;
ps*=Sp[i];//求Ps
// b[i]=ps;
}
cout<<“Fs=“< gFs=Fs;
float?l=log(1/ps)/log(2);
if(l>(int)l)l=(int)l+1;
else?l=int(l);
// cout< int?d[20];
//float?x;
int?m=0;
while(l>m)//轉換為二進制
{
Fs=2*Fs;
if(Fs>1)
{
Fs=Fs-1;
d[m]=1;
}
else?if(Fs<1)d[m]=0;
else?{d[m]=1;break;}
?m++;
}
int?z=m;
if(m>=l)
{
while(1)
{ ?? ??
d[m-1]=(d[m-1]+1)%2;//最后位加1
if(d[m-1]==1)break;
else?m--; ??
}
}
//if(d[m-1]==)
//cout< cout<<“s=“;
for(int?e=0;e cout< cout<
// return?Fs;
}
void
評論
共有 條評論