



É necessário estar declarado SysUtils na seção uses,
em versões unicode declare System.SysUtils.
A função realiza a conversão de uma string binária para Integer.
Abaixo segue o código fonte da função:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function BinToDec(Valor: String): Cardinal; 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 := Round(Decimal); end; |
Exemplos de uso:
1 2 3 4 5 6 7 8 9 10 11 | procedure TForm1.Button1Click(Sender: TObject); begin // 210 ShowMessage(IntToStr(BinToDec('11010010'))); // 192 ShowMessage(IntToStr(BinToDec('11000000'))); // 41 ShowMessage(IntToStr(BinToDec('101001'))); end; |