你没有理解在pascal中,16进制只是一种写法而已
看下边的例子
strtoint('$ff')=255
inttohex($ff,2)='FF'

解决方案 »

  1.   

    你没有理解在pascal中,16进制只是一种写法而已
    看下边的例子
    strtoint('$ff')=255
    inttohex($ff,2)='FF' 
    inttohex(255,4)='00FF' 
      

  2.   

    inttohex(strtoint('$1234'),2))= '1234'
    inttohex(strtoint('1234'),2))= '4D2'
      

  3.   

    nne998是不是有毛病阿????
      

  4.   

    procedure TForm1.myButton1Click(Sender: TObject);
    var
     str,hex:string;
     i:integer;
    begin
      str:='中国';
      for i:=1 to Length(str) do
        hex:=hex+inttohex(ord(str[i]),2);
      showmessage(hex);
    end;
      

  5.   

    to galeboy(狂风小子):
    那再把十六进制变回 '中文' 呢???
      

  6.   

    使用function StrToHex(Str : String) : String;
    很好用的
      

  7.   

    to bill_lasker():没有StrToHex这个函数。配合galeboy(狂风小子)的方法,我自己解决了:
    '中文'---->hex
    hex ------> '中文'procedure TForm1.Button1Click(Sender: TObject);
    var
    str,hex:string;
    i:integer;
    begin
      str:='中国';
      for i:=1 to Length(str) do
        hex:=hex+inttohex(ord(str[i]),2);
      edit1.Text:=hex;  hex:='';
      str:='';
      for i:=1 to length(edit1.text) do
      begin
            if i div 2<>i/2 then
            begin
                    hex:=copy(edit1.text,i,2);
                    str:=hex+chr(strtoint('$'+hex));
            end;
      end;
      edit2.text:=str;end;
      

  8.   

    自己整理一遍:function StrToHex(sStr:string):string;   //如:  strtohex('中文') 输出:D6D0CEC4      
    var
        i:integer;
        sHex:string;
    begin
        if sStr='' then exit;
        for i:=1 to Length(sStr) do
            sHex:=sHex+inttohex(ord(sStr[i]),2);
        result:=sHex;
    end;function HexToStr(sHex:string):string;    //如:hextostr('D6D0CEC4')  无'$'    输出:中文
    var
        i:integer;
        sStr:string;
    begin
        for i:=1 to length(sHex) do
        begin
            if i div 2<>i/2 then
                    sStr:=sStr+chr(strtoint('$'+copy(sHex,i,2)));
        end;
        result:=sStr;
    end;