Einzelnen Beitrag anzeigen

pszopp

Registriert seit: 7. Sep 2005
Ort: Alsdorf
95 Beiträge
 
Delphi 2010 Professional
 
#3

Re: umwandlung von dualzahlen zu dezimalzahlen

  Alt 26. Jun 2006, 09:44
Wilkommen in der DP,

Ich gehe mal davon aus, dass die Dual-Zahl als String vorliegt:

Delphi-Quellcode:
uses Math

...

function BinToInt(const BinStr : String) : Integer;
var lk : Integer;
begin

  Result := 0;
  for lk := length(BinStr) downto 1 do begin
    if (BinStr[lk] = '1') then
      Result := Result + Round(Power(2, (length(BinStr) - lk)));
  end; // for lk

end; // BinToInt
Dieses kleine Code-Schnipsel durchläuft die Binäre Zahl von rechts nach links.
Wenn eine eins gefunden wird, wird das Ergebis um die passende Deziamlzahl erhöht.


Viele Grüße,
pszopp
www.pstipp.de | Tippseite zur Formel 1 und Fußball WM/EM - kostenlos und Just-For-Fun
  Mit Zitat antworten Zitat