全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1578
推到 Plurk!
推到 Facebook!

如何把ASKII碼轉16進位

尚未結案
dsp
一般會員


發表:14
回覆:23
積分:7
註冊:2003-10-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-26 22:13:22 IP:61.217.xxx.xxx 未訂閱
請問各位前輩 如何開起一個*.TXT檔案打開把整個ASKII碼轉成16進位碼 再存在一個*.TXT檔,還有16進位碼轉成ASKII碼再存在一個*.TXT檔 各位前輩是否教一下,感謝各位 謝謝
shieh2700
高階會員


發表:0
回覆:127
積分:100
註冊:2002-06-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-27 01:20:42 IP:61.216.xxx.xxx 未訂閱
procedure H2A(HexFile, AsciiFile: string);
var
  h, a  : TextFile;
  s1, s2: char;
begin
  AssignFile( a, AsciiFile );
  AssignFile( h, HexFile );
  Reset( h );
  Rewrite( a );
  while NOT eof( h ) do begin
    Read( h, s1, s2 );
    Write( a, Chr( StrToInt( '$' s1 s2 ) ) );
  end;
  CloseFile( h );
  CloseFile( a );
end;    procedure A2H(AsciiFile, HexFile: string);
var
  h, a  : TextFile;
  s     : char;
begin
  AssignFile( a, AsciiFile );
  AssignFile( h, HexFile );
  Reset( a );
  Rewrite( h );
  while NOT eof( a ) do begin
    Read( a, s );
    Write( h, Format( '%.2x', [ Ord( s ) ] ) );
  end;
  CloseFile( h );
  CloseFile( a );
end;
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-10-27 21:34:23 IP:218.32.xxx.xxx 未訂閱
dsp 你好 :    既然寫了, 姑且參考看看...    
procedure TextToHex;
var
  Txt,Hex:TStrings;
  ps,pd: PChar;
begin
  Txt := TStringList.Create;
  Hex := TStringList.Create;
  try
    Txt.LoadFromFile('E:\Text.TXT');
    ps := PChar(Txt.Text);
    GetMem(pd, 2 * Length(Txt.Text));
    BinToHex(ps,pd,Length(Txt.Text));
    Hex.Text := StrPas(pd);
    Hex.SaveToFile('E:\Hex.TXT');
  finally
    FreeMem(pd);
    Txt.Free;
    Hex.Free;
  end;
end;    procedure HexToText;
var
  Txt,Hex:TStrings;
  ps,pd: PChar;
  L : Integer;
begin
  Txt := TStringList.Create;
  Hex := TStringList.Create;
  try
    Hex.LoadFromFile('E:\Hex.TXT');
    ps := PChar(Hex.Text);
    L := Trunc(Length(Hex.Text) / 2);
    GetMem(pd,L);
    HexToBin(ps,pd,L);
    Txt.Text := StrPas(pd);
    Txt.SaveToFile('E:\Text.TXT');
  finally
    FreeMem(pd);
    Txt.Free;
    Hex.Free;
  end;
end;
系統時間:2024-07-05 3:56:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!