Thema: Delphi bin2dec

Einzelnen Beitrag anzeigen

Benutzerbild von APP
APP

Registriert seit: 24. Feb 2003
Ort: Graz (A)
705 Beiträge
 
Delphi 7 Enterprise
 
#5
  Alt 5. Apr 2003, 19:01
Hallo,
wenn Du es noch 'komplizierter' möchtest, dann schau mal:

Delphi-Quellcode:
PROCEDURE TForm1.Button1Click(Sender: TObject);
VAR
   i : integer;
   bin : Extended;
   Dec : Extended;
BEGIN
   bin := 1;
   dec := 0;
   FOR i := 1 TO length(Edit1.text) DO
      BEGIN
         bin := intpower(2, i - 1);
         IF Edit1.text[i] = '1THEN
            dec := dec + bin;
      END;
   showMessage(FloatToStr(dec));
END;
Du brauchst eine TEdit und einen TButton

Achtung: das LSB ist links! D.H. 1011 -> 2^0 + 2^2 + 2^3 = 1 + 4 + 8 = 13
Armin P. Pressler

BEGIN
...real programmers are using C/C++ - smart developers Delphi;
END;
  Mit Zitat antworten Zitat