请用delphi写一下怎么实现

解决方案 »

  1.   

    具体一点吧
    我做过一个将文件流转成字串的程序不知你能否用procedure StrToStream(const sIn:string;var sm:TMemoryStream);
    var
      nTemp,nCount:integer;
      nLp:integer;
      s1,s2:string;
      bTemp:Byte;
    begin
      if sm=nil then Exit;
      if (Length(sIn) mod 2)<>0 then Exit;
      nCount:=Round(Length(sIn)/2);
      for nLp:=0 to nCount-1 do
      begin
        bTemp:=0;
        s1:=Copy(sIn,nLp*2+1,1);
        s2:=Copy(sIn,nLp*2+2,1);
        if (s1='') or (s2='') then continue;
        if s1='A' then nTemp:=10
        else if s1='B' then nTemp:=11
        else if s1='C' then nTemp:=12
        else if s1='D' then nTemp:=13
        else if s1='E' then nTemp:=14
        else if s1='F' then nTemp:=15
        else nTemp:=StrToInt(s1);
        bTemp:=bTemp+nTemp*16;
        if s2='A' then nTemp:=10
        else if s2='B' then nTemp:=11
        else if s2='C' then nTemp:=12
        else if s2='D' then nTemp:=13
        else if s2='E' then nTemp:=14
        else if s2='F' then nTemp:=15
        else nTemp:=StrToInt(s2);
        bTemp:=bTemp+nTemp;
        sm.Position:=sm.Size;
        sm.writebuffer(bTemp,1);
      end;
      sm.Position:=0;
    end;function StreamToStr(sm:TMemoryStream):string;
    var
      nLp:integer;
      bTemp:Byte;
    begin
      result:='';
      if sm=nil then Exit;
      for nLp:=0 to sm.Size-1 do
      begin
        sm.Position:=nLp;
        sm.Read(bTemp,1);
        result:=result+IntToHex(bTemp,2);
      end;
    end;
      

  2.   

    就是16进制数比如1A,转换成ascii码。1对应ascii的49,A对应字母A,ascii值65转换过来就是1A——>49,65反过来也一样转换
      

  3.   

    HexToAscII
    Chr(HexToInt('1A'))
    AscII to Hex
    IntToHex(Ord('A'))
      

  4.   

    sorry
    AscII to Hex
    IntToHex(Ord('A'),2)
      

  5.   

    function HexToAsc(Hex: string): string;
    var
      i: integer;
    begin
      for i := 1 to Length(Hex) do
        Result := Result + IntToStr(Ord(Hex[i]));
    end;function AscToHex(Asc: string): string;
    var
      B: string[2];
      i: integer;
    begin
      if Length(Asc) mod 2 <> 0 then raise Exception.Create('Error Asc string');
      for i := 0 to Length(Asc) div 2 - 1 do
      begin
        B := Copy(Asc, i * 2 + 1, 2);
        Result := Result + Chr(StrToInt(B));
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Caption := AscToHex(HexToAsc('1A0F'));
    end;楼猪很懒