function DecToBin(const IntValue: Integer): String;
var
  lValue: Integer;
begin
  Result := '';
  lValue := IntValue;
  while lValue > 2 do
  begin
    Result := Chr(48 + (lValue mod 2)) + Result;
    lValue := lValue div 2;
  end;
  Result := Chr(48 + lValue) + Result;
end;

function BinToDec(const BinValue: String): Integer;
var
  lValue: String;
begin
  Result := 0;
  lValue := BinValue;
  while Length(lValue) > 0 do
  begin
    Result := Result + ((Ord(lValue[1]) - 48) * (1 shl (Length(lValue) - 
1)));
    System.Delete(lValue, 1, 1);
  end;
end;

Sds.


>From: Julio Cesar Quierati <[EMAIL PROTECTED]>
>Reply-To: delphi-br@yahoogrupos.com.br
>To: delphi br <delphi-br@yahoogrupos.com.br>
>Subject: [delphi-br] Funçao que tranforme Binario em INTEIRO
>Date: Tue, 23 Jan 2007 10:13:53 -0300 (ART)
>
>   Olá, pessoal.
>
>   estou precisando de uma função para transformar binario em inteiro, 
>utilizei estas duas funções abaixo mas nao estao retornando os valores 
>corretos, alguem sabe de outra que funcione ou o que esta ocorrendo com 
>essas funções ?
>
>
>   Function BinToInt(valor: string):longint;
>   var i, tamanho, np : Integer;
>   Begin
>   Result :=0;
>   tamanho := Length(valor);
>   For i:=0 to Tamanho-1 do
>   Begin
>   NP := strtoint(valor[tamanho-1]);
>   Result := Result + NP *Trunc(Power(2,i));
>   end;
>   end;
>
>   Function bintoint( valor:string): integer;
>   var i, tamanho : integer;
>   begin
>   result :=0;
>   tamanho:= length(valor);
>   for i:= tamanho downto 0 do
>     begin
>       if copy(valor,i,1)='1' then
>          begin
>             result := result +(1 shl i);
>           end;
>      end;
>   end;
>
>
>   no mais Grato,
>
>   Julio Quierati
>
>  __________________________________________________
>Fale com seus amigos  de graça com o novo Yahoo! Messenger
>http://br.messenger.yahoo.com/
>
>[As partes desta mensagem que não continham texto foram removidas]
>

_________________________________________________________________
MSN Busca: fácil, rápido, direto ao ponto.  http://search.msn.com.br

Responder a