my ($bits, $j, @used) = ($i, 0); while ($bits) { push @used, $n[$j] if $bits & 1; $bits >>= 1, ++$j; }