Fórum transformar Binario em decimal #61851
07/05/2007
0
preciso transformar numeros Binarios em Decimal, até tenho um metodo em Delphi pra isso mais preciso fazer em C++.
eis o metodo em Pascal:
function BinToInt(Value: String): LongInt;
{Converte um numero binário em Inteiro}
var
i,Size: Integer;
begin
Result := 0;
Size := Length(Value);
for i:= Size downto 0 do
begin
if Copy(Value,i,1)= ´1´ then
begin
Result := Result + (1 shl i);
end;
end;
end;
se alguem tiver outra ideia será bem vinda tb
Fabiano Góes
Curtir tópico
+ 0Posts
08/05/2007
Rodc
int __fastcall BinToHex(AnsiString Value)
{
if (Value.Length() > 32)
throw Exception("Valor maior que 32 bytes");
int retorno = 0;
for (int x=Value.Length(); x > 0; x--)
retorno = retorno | (StrToInt(Value.SubString(x, 1)) << Value.Length()-x);
return retorno;
}
Gostei + 0
08/05/2007
Fabiano Góes
vou testar !!!
obrigado !!!
Gostei + 0
25/05/2012
Anderson Mafra
preciso transformar numeros Binarios em Decimal, até tenho um metodo em Delphi pra isso mais preciso fazer em C++.
eis o metodo em Pascal:
[code:1:05a92d2cfe]
function BinToInt(Value: String): LongInt;
{Converte um numero binário em Inteiro}
var
i,Size: Integer;
begin
Result := 0;
Size := Length(Value);
for i:= Size downto 0 do
begin
if Copy(Value,i,1)= ´0´ then
begin
Result := Result + (1 shl i);
end;
end;
end;
[/code:1:05a92d2cfe]
se alguem tiver outra ideia será bem vinda tb
Gostei + 0
25/05/2012
Bruno Leandro
function BinToDec(valor: String): string;
var
decimal: real;
x,y: integer;
begin
decimal := 0;
y := 0;
for x := Length( valor ) DownTo 1 Do
Begin
decimal := decimal + ( StrToFloat( valor[x] ) ) * Exp( y * Ln( 2 ) );
y := y + 1;
End;
result := FloatToStr( decimal );
End;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)