网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.两个delphi下遍历指定目录下指定.
.Delphi的拨号连接类.
.在Delphi中编写控件的基本方法.
.WINDOWS编程技巧之DELPHI篇.
.tlistview使用--拖放操作.
.个人观点随笔-RAD和面向对象.
.如何获取本地HTML文件的标题,超级.
.delphi中的split函数.
.Delphi使用ABC.
.公历到农历的转换法.
.关于开发系统后门软件的几点思路.
.获得Windows的版本信息.
.Delphi点滴.
.让窗体在执行了“显示桌面”以后.
.实现StatusBar的Flat风格.
.不知您是笨蛋,还是我是笨蛋,关.
.一个DELPHI的MemoryManager.
.半透明窗体的制作.
.Delphi中使用资源文件.
.组件制作之五(托盘组件).

算术编码算法

发表日期:2006-2-4


算术编码算法
算术编码是把一个信源表示为实轴上0和1之间的一个区间,信源集合中的每一个元素都用来缩短这个区间。
   算术编码的过程如下:
(1)       设定编码区间的高段为h,编码区间的长度为g,EndC为编码字符分配的高段,StartC
为字符分配区间的低端。
(2)       根据有限的信源估算出各元素的概率。
(3)       杜宇编码的元素A1,根据(2)估算的概率和区间,计算出该元素编码后的新的l,和h。其公式如下:
         h = StartC + g* K;
         l = Endc + g* K1;
其具体程序如下:           
             
const  Ca = 0.2;  Ce = 0.3;
      Ci = 0.2;  Co = 0.2;
      Cu = 0.1;
var
  Form1: TForm1;
   s: string;
   StartC, EndC: Extended;
implementation
{$R *.dfm}
procedure ConvertTo(s: string; var StartC, EndC: Extended);{将字符串变为数值}
var n, i: integer;
    c: char;
    g: Extended;
begin
    StartC := 0;
    EndC := 1;
    n := Strlen(Pchar(s));
    for i := 1 to n do
    begin
       c := s[i];
       g := EndC - StartC;
       case C of
       'a':
         begin
            EndC :=StartC  + g * Ca;
            StartC := StartC + g * 0;
         end;
       'e':
          begin
            EndC := StartC + g * (Ca + Ce);
            StartC := StartC + g * Ca;
         end;
       'i':
          begin
            EndC := StartC + g * (Ca + Ce + Ci);
            StartC := StartC + g * (Ca + Ce);
         end;
       'o':
          begin
            EndC := StartC + g * (Ca + Ce + Ci + Co);
            StartC := StartC + g * (Ca + Ce + Ci);
         end;
       'u':
          begin
            EndC := StartC + g * (Ca + Ce + Ci + Co + Cu);
            StartC := StartC + g * (Ca + Ce + Ci + Co);
         end;
       else
           begin
            Showmessage(' 输入的字符串有误 ');
            exit;
           end;
      end;
    end;
end;
procedure NemuricalToStr(var s: String; var StartC, EndC: Extended);
{将数值转换为字符串}
const eps = -1e-5;
begin
  if StartC-0.2 < -eps  then
    if (EndC- 0.2<= -eps) and (EndC > StartC) then
    begin
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'a';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
   end;
  if (StartC- 0.2 >= eps) and (StartC-0.5 < -eps) then
    if (EndC-0.5<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.2;
       EndC := EndC - 0.2;
       StartC := StartC / 0.3;
       EndC := EndC / 0.3;
       s := s + 'e';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC- 0.5>= eps) and (StartC- 0.7< -eps) then
    if (EndC-0.7<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.5;
       EndC := EndC - 0.5;
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'i';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC-0.7 >= eps) and (StartC-0.9 < -eps) then
    if (EndC-0.9<=-eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.7;
       EndC := EndC - 0.7;
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'o';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC -0.9>=eps) and (StartC-1 < -eps) then
    if (EndC-1<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.9;
       EndC := EndC - 0.9;
       StartC := StartC / 0.1;
       EndC := EndC / 0.1;
       s := s + 'u';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
   s := Edit1.Text;
   ConvertTo(s,StartC,EndC);
   Edit2.Text := FloattoStr(StartC);
   Edit3.Text := FloattoStr(EndC);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
    s := '';
    StartC := StrToFloat(Edit2.Text);
    EndC := StrtoFloat(Edit3.Text);
    NemuricalToStr(s,StartC,Endc);
    Edit1.Text := s;
end;
end.
上一篇:在Delphi中如何使用RC文件中的字符串表 人气:4409
下一篇:TreeView使用笔记 人气:4461
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐