Forum: Programmieren allgemein
by nicodex,
3. Sep 2008
Kein Ursache, der Code lag so in meinem Archiv ;)
Forum: Programmieren allgemein
by nicodex,
3. Sep 2008
{$RANGECHECKS OFF}
{$OVERFLOWCHECKS OFF}
function SidewaysAddition32(AValue: LongWord): LongWord; inline;
begin
Result := AValue - ((AValue shr 1) and $55555555);
Result := (Result and $33333333) + ((Result shr 2) and $33333333);
Result := (Result + (Result shr 4)) and $0F0F0F0F;
Result := (Result * $01010101) shr 24;
end;
Forum: Programmieren allgemein
by nicodex,
3. Sep 2008
Im Endeffekt willst du die Bits zählen. Dafür gibt es Optimierungen...
//
// A generalization of the best bit counting method (sideways addition)
// to integers of bit widths upto 128 (parameterized by type T) is this:
//
// v := v - ((v shr 1) and T(not T(0) div 3));
// v := (v and T(not T(0) div 15 * 3)) + ((v shr 2) and T(not T(0) div 15 * 3));
// v := (v + (v shr 4)) and T(not T(0)...