lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, May 24, 2013 at 1:09 AM, Finn Wilcox <finnw@finnw.me.uk> wrote:
On 24/05/2013 06:29, Vaughan McAlley wrote:
>
> I’d like to iterate through all 40-bit binary numbers that have a
> Hamming weight of 25 (ie. 25 of the bits are set to 1).

I think this may be what you want:

http://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation



See also http://www.hackersdelight.org/basics2.pdf (search for "snoob" around the end of 2-1) I don't know if the algorithm is any better, but the book explains some of the details.