Compute the lexicographically next bit permutation

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

Suppose we have a pattern of N bits set to 1 in an integer and we want
the next permutation of N 1 bits in a lexicographical sense. For
example, if N is 3 and the bit pattern is 00010011, the next patterns
would be 00010101, 00010110, 00011001,00011010, 00011100, 00100011, and
so forth.

How could this be implemented in ruby?

-- 
Posted via http://www.ruby-forum.com/.