www.pudn.com > hanzi.rar > Unit1.pas


unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Edit1: TEdit; 
    Edit2: TEdit; 
    Button2: TButton; 
    Label1: TLabel; 
    Label2: TLabel; 
    Edit3: TEdit; 
    Edit4: TEdit; 
    Label3: TLabel; 
    Label4: TLabel; 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
function hextostr(hex:string):string; 
var i,j,k:integer;  
begin  
  k:=length(hex) div 2; 
  for i:=1 to k do 
  begin 
    case hex[2*i-1] of  
      '0'..'9':j:=strtoint(hex[2*i-1]);  
      'a'..'f':j:=ord(hex[2*i-1])-87;  
      'A'..'F':j:=ord(hex[2*i-1])-55;  
    end; 
 
    case hex[2*i] of  
      '0'..'9':j:=j*16+strtoint(hex[2*i]);  
      'a'..'f':j:=j*16+ord(hex[2*i])-87; 
      'A'..'F':j:=j*16+ord(hex[2*i])-55;  
    end;  
    result:=result+chr(j); 
  end; 
end; 
function strToHex(str:string):string; 
var 
  i,k,a:integer; 
  ch:char; 
begin 
  k:=length(str); 
  for i:=1 to K do 
  begin 
    ch:=str[i]; 
    a:=Ord(ch); 
    result:=result+IntToHex(a,2); 
  end; 
end; 
 
{$R *.dfm} 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
   edit2.Text:=hextostr(edit1.Text); 
end; 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
   edit4.Text:=strtohex(edit3.Text); 
end; 
 
End.