我从串口得到这一串数据,
ASCII显示为: 02 30 30 30 31 30 30 45 39 31 31 42 33 41 45 03 
怎么转为16进制显示:000100E911B3AE

解决方案 »

  1.   

    begin     0       0       0       1       0       0    ……     E     end
    Chr(02)+Chr(30)+Chr(30)+Chr(30)+Chr(31)+Chr(30)+Chr(30)+……+Chr(45)+Chr(30)
      

  2.   

    function HexToAscii(s: string): string;
    var
      i: integer;
    begin
      Result := EmptyStr;
      for i := 1 to Length(S) do
      begin
        if ((i mod 2) = 1) then
          Result := Result + Chr(StrToInt('0x' + Copy(S, i, 2)));
      end;
    end;
      

  3.   

    相反的是:
    function asciitohex(rep:string):string;var Li, i : Integer;
        begin
    Li := Length(rep); 
    if Li = 0 then Exit;for i := 1 to Li do
            begin
    Result:=Result+IntToHex(Ord(rep[i]),2)+' ';
            end;
    end;