myamanda

博客园 首页 新随笔 联系 订阅 管理
function HexaToDecimal(Hexa:string):longint;
const
   ValoresHexa : array['A'..'F'] of integer = (10,11,12,13,14,15);
var
   nDecimal : longint;
   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)));
   HexaToDecimal := nDecimal;
end;
posted on 2009-08-05 11:33  myamanda  阅读(401)  评论(0编辑  收藏  举报