Einzelnen Beitrag anzeigen

Benutzerbild von BlackJack
BlackJack

Registriert seit: 2. Jul 2005
Ort: Coesfeld
246 Beiträge
 
Delphi 2005 Personal
 
#2

Re: Div 2 durch Subtraktion

  Alt 24. Apr 2006, 20:00
das könnte man mit shifts machen:

Delphi-Quellcode:
var Zahl, ZahlDiv2: Integer;
begin
Zahl := 1024;
ZahlDiv2 := Zahl shr 1; //ZahlDiv2 = 512
end;
oder allgemein

Code:
Zahl div 2^k = Zahl shr k
wenn ich mich nicht irre

wobei ich denke dass der Delphi-kompiler aus einem div 2 eh ein shr 1 machen wird.

edit: für multiplikation geht das übrigens auch:
Code:
Zahl * 2^k = Zahl shl k
See my shadow changing, stretching up and over me.
Soften this old armor. Hoping I can clear the way
By stepping through my shadow, coming out the other side.
Step into the shadow. Forty six and two are just ahead of me.
  Mit Zitat antworten Zitat