{ Efetua a conversão de um valor em hexadecimal para decimal.
  Precisa da unit Math. }
function HexToDec(AValue: String): LongInt;
var
  lDig1, lDig2: Char;
  lValDig1, lValDig2: ShortInt;
begin
  while Boolean(Length(AValue) mod 2) do
    AValue := '0' + AValue;
  Result := 0;
  while Boolean(Length(AValue)) do
  begin
    lDig1 := Copy(AValue, 1, 1)[1];
    lDig2 := Copy(AValue, 2, 1)[1];

    lValDig1 := IfThen(lDig1 in ['A'..'F'], Ord(lDig1) - 55,
      StrToIntDef(lDig1, -1));
    lValDig2 := IfThen(lDig2 in ['A'..'F'], Ord(lDig2) - 55,
      StrToIntDef(lDig2, -1));

    if (lValDig1= -1) or (lValDig2 = -1) then  // Número hexadecimal 
inválido!
    begin
      Result := -1;
      Break;
    end;

    Result := Result + ((lValDig1 shl 4) or lValDig2);
    System.Delete(AValue, 1, 2);
  end;
end;


{ Efetua a conversão de um valor decimal para o seu equivalente em 
hexadecimal }
function DecToHex(AValue: LongInt): String;
const
  Mods: array [0..$FF] of Char = '0123456789ABCDEF';
var
  lDone: Boolean;
begin
  Result := '';
  lDone := False;
  while not lDone do
  begin
    Result := Mods[AValue and $0F] + Result;
    AValue := AValue shr 4;
    lDone := (AValue < 16);
  end;
  Result := Mods[AValue] + Result;
end;

Sds.

_________________________________________________________________
MSN Messenger: converse com os seus amigos online. 
http://messenger.msn.com.br



-- 
<<<<< FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM >>>>>

<*> Para ver as mensagens antigas, acesse:
    http://br.groups.yahoo.com/group/delphi-br/messages

<*> Para falar com o moderador, envie um e-mail para:
    [EMAIL PROTECTED]
 
Links do Yahoo! Grupos

<*> Para visitar o site do seu grupo na web, acesse:
    http://br.groups.yahoo.com/group/delphi-br/

<*> Para sair deste grupo, envie um e-mail para:
    [EMAIL PROTECTED]

<*> O uso que você faz do Yahoo! Grupos está sujeito aos:
    http://br.yahoo.com/info/utos.html

 


Responder a