十六进制数据转换成十进制数据,如将AB转换成十进制数.

解决方案 »

  1.   

    function HexToDec(Hexa:string):integer;
    const
      ValoresHexa:array['A'..'F'] of integer=(10,11,12,13,14,15);
    var
      nDecimal:integer;
      nIndex:byte;
    begin
      nDecimal:=0;
      Hexa:= Uppercase(Hexa);
      for nIndex:=length(Hexa) downTo 1 do
        if Hexa[nIndex] in ['0'..'9'] then
          nDecimal:=nDecimal+StrToInt(Hexa[nIndex])*
                    Trunc(Exp(Length(Hexa)-nIndex)*ln(16)))
        else
          nDecimal:=nDecimal+ValoresHexa[Hexa[nIndex]]*
                    Trunc(Exp(Length(Hexa)-nIndex)*ln(16)));
      result:=nDecimal;
    end;
      

  2.   

    http://expert.csdn.net/Expert/topic/1330/1330990.xml?temp=.5624964