转换前31 30 33 39 2E 31 38 37
转换后1039.187
请问如何实现?
另问用TFileStream类如何实现读取后转换,请大家多多指教

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses
      StrUtils;function xxx(s:string):string;
    var
      i:integer;
    begin
      result:='';
      for i:=0 to Round(length(s)/3)-1 do
      begin
        result:=result+Chr(StrToInt('$'+LeftStr(PChar(@PChar(s)[i*3]),2)))
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(xxx('31 30 33 39 2E 31 38 37 '));
    end;end.
      

  2.   

    谢谢truedogface(^(o.o)^) 的回帖,转换知道了,哪位再能说一下如何在二进制文件里按字节读取一组连续的16进制数值?如上例中的31 30 33 39 2E 31 38 37,能否用TFileStream实现呢?我听高手说按字节读文件要加什么编译开关?请知道的兄弟姐妹帮一下忙吧。。
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        OpenDialog1: TOpenDialog;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      fs:TFileStream;
      b:Byte;
    begin
      if(not OpenDialog1.Execute)then
        exit;  fs:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead or fmShareDenyNone);
      try
        while(fs.Position<>fs.Size)do
        begin
          fs.Read(b,1);
          //ShowMessage(IntToHex(b,2));  //可以显示出来看看
        end;
      finally
        fs.Free;
      end;
    end;end.