Autor Beitrag
lkz633
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: So 12.10.03 01:17 
Hallo,

die Ueberschrift macht es vermutlich schon deutlich, ich moechte eine Schleife bis 2^i laufen lassen.

Alle Versuche schlugen jedoch fehl, da ich immer Extended fuer meine Berechnungen rausbekomme, da immer eine Multiplikation vorkommt.

Auch eine Typumwandlung schlug fehl. Der Wert wird (2^7)+1 nicht uebersteigen.

Was kann ich tun?

Dank und Gruss
lkz633
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: So 12.10.03 01:40 
Da der Computer sehr gerne mit 2er Potenzen arbeitet, hat er natürlich auch demensprechende Befehle:

ausblenden Quelltext
1:
for i := 0 to (1 shl x) do					



SHL steht für ShiftLeft.

Das funktioniert so:
0000 0001 SHL 1 = 0000 0010
0000 0001 SHL 2 = 0000 0100
0000 0001 SHL 3 = 0000 1000
...

_________________
Ist Zeit wirklich Geld?
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: So 12.10.03 10:20 
Titel: hmm,
in solchen Fällen hilft sehr oft mit round das Ergebnis zur Integer zu machen ;)

_________________
mfg. Joel
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: So 12.10.03 11:27 
Titel: Re: hmm,
JoelH hat folgendes geschrieben:
in solchen Fällen hilft sehr oft mit round das Ergebnis zur Integer zu machen ;)


:?: warum integer nach athen tragen :?:

_________________
mfg.
mâximôv
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: So 12.10.03 12:43 
AndyB hat folgendes geschrieben:

ausblenden Quelltext
1:
for i := 0 to (1 shl x) do					



SHL steht für ShiftLeft.


Super, herzlichen Dank, das ist natuerlich die schoenste und eleganteste Loesung. (Vermutlich auch die schnellste??)

Gruss lk633