请问各位DELPHI里有没有把十六进制转换为二进制的函数。

解决方案 »

  1.   

    纠正下是请问各位DELPHI里有没有把十六进制转换为十进制的函数。
      

  2.   

    好象只有十进制转换十六进制的IntToHex、需要转换吗、直接就可以用、或者StrToInt('$' + IntToStr(Value));
      

  3.   

    进制转换代码,试试看,我还没试过。
    function HexToInt(Hex : string) : Cardinal; 
    const cHex = '0123456789ABCDEF'; 
    var mult,i,loop : integer; 
    begin 
    result := 0; 
    mult := 1; 
    for loop := length(Hex) downto 1 do begin 
    i := pos(Hex[loop],cHex)-1; 
    if (i < 0) then i := 0; 
    inc(result,(i*mult)); 
    mult := mult * 16; 
    end; 
    end; function IntToBin(Value : integer; NumBits : byte) : string; 
    var lp0 : integer; 
    begin 
    result := ''; 
    for lp0 := 0 to NumBits-1 do begin 
    if ((Value and (1 shl (lp0))) <> 0) then begin 
    result := #$31 + result; 
    end else result := #$30 + result; 
    end; 
    end; function BinToInt(Bin : string) : integer; 
    var mult,lp0 : integer; 
    begin 
    result := 0; 
    mult := 0; 
    for lp0 := length(Bin) downto 1 do begin 
    if Bin[lp0] = #$31 then begin 
    inc(result,(1 shl mult)); 
    end; 
    inc(mult); 
    end; 
    end; function BinToHex(Bin : string; Digits : integer) : string; 
    begin 
    result := IntToHex(BinToInt(Bin),Digits); 
    end; function HexToBin(Hex : string; NumBits : byte) : string; 
    begin 
    result := IntToBin(HexToInt(Hex),NumBits); 
    end; // Below are also some code usefull for testing if a string is in binary, hex or decimal form. function IsStrDec(Value : string) : boolean; 
    var lp0 : integer; 
    begin // returns true on empty strings, since equal to zero 
    result := true; 
    for lp0 := 1 to length(Value) do begin 
    result := result and ((Ord(Value[lp0]) >= $30) and (Ord(Value[lp0]) <= $39)); 
    end; 
    end; function IsStrHex(Value : string) : boolean; 
    var lp0 : integer; 
    begin 
    result := true; 
    for lp0 := 1 to length(Value) do begin 
    case Ord(Upcase(Value[lp0])) of 
    $30..$39, $41..$46: result := result and true; 
    else 
    result := false; 
    end; 
    end; 
    end; function IsStrBin(Value : string) : boolean; 
    var lp0 : integer; 
    begin 
    result := true; 
    for lp0 := 1 to length(Value) do begin 
    case Ord(Upcase(Value[lp0])) of 
    $30..$31: result := result and true; 
    else 
    result := false; 
    end; 
    end; 
    end; 
      

  4.   

    StrToInt('$' + IntToStr(Value));