Hey there
Hier zwei allgemeine Lösungen:
Delphi-Quellcode:
function ElemCount(const ASet; const Size: Cardinal): Byte;
var
X, I: Integer;
begin
Result:= 0;
X:= Cardinal(ASet);
for I:= 0 to Pred(Size shl 3) do
begin
if Odd(X) then Inc(Result);
X:= X shr 1;
end;
end;
function SmallestElem(const ASet; const Size: Cardinal; out Elem): Boolean;
var
X, I: Integer;
begin
Result:= False;
X:= Cardinal(ASet);
for I:= 0 to Pred(Size shl 3) do
begin
if Odd(X) then
begin
Byte(Elem):= I;
Result:= True;
Exit;
end;
X:= X shr 1;
end;
end;
Gruss
Shaman