wie gesagt, die Bereichsprüfung sollte besser nicht unterschlagen werden (in
ASM gibt's damit aber keine Probleme

)
Delphi-Quellcode:
Function IsPowerOfTwo(i: Cardinal): Boolean; Inline;
Begin
{$IFOPT R+}
{$R-}
Result := (i <> 0) and (i and Pred(i) = 0);
{$R+}
{$ELSE}
Result := (i <> 0) and (i and Pred(i) = 0);
{$ENDIF}
End;
// oder
Function IsPowerOfTwo(i: Cardinal): Boolean; Inline;
Begin
{$IFOPT R+}
{$DEFINE IsPowerOfTwo_RangechecksOn}
{$R-}
{$ELSE}
{$UNDEF IsPowerOfTwo_RangechecksOn}
{$ENDIF}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$IFDEF IsPowerOfTwo_RangechecksOn}
{$R+}
{$ENDIF}
End;
// oder (wobei bei in meinen Codes _TEMP_ immer frei ist ... nicht daß man da mal ausversehn was überschreibt)
Function IsPowerOfTwo(i: Cardinal): Boolean; Inline;
Begin
{$IFOPT R+} {$R-} {$DEFINE _TEMP_} {$ELSE} {$UNDEF _TEMP_} {$ENDIF}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$IFDEF _TEMP_} {$R+} {$ENDIF}
End;
Delphi-Quellcode:
Function IsPowerOfTwo(i: Integer): Boolean; Inline;
Begin
{$IFOPT R+}
{$R-}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$R+}
{$ELSE}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$ENDIF}
End;
// oder
Function IsPowerOfTwo(i: Integer): Boolean; Inline;
Begin
{$IFOPT R+}
{$DEFINE IsPowerOfTwo_RangechecksOn}
{$R-}
{$ELSE}
{$UNDEF IsPowerOfTwo_RangechecksOn}
{$ENDIF}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$IFDEF IsPowerOfTwo_RangechecksOn}
{$R+}
{$ENDIF}
End;
// oder ...
Function IsPowerOfTwo(i: Integer): Boolean; Inline;
Begin
{$IFOPT R+} {$R-} {$DEFINE _TEMP_} {$ELSE} {$UNDEF _TEMP_} {$ENDIF}
Result := (i <> 0) and (i and Pred(Abs(i)) = 0);
{$IFDEF _TEMP_} {$R+} {$ENDIF}
End;
Ein Therapeut entspricht 1024 Gigapeut.