??? 12/13/06 15:51 Read: times |
#129418 - Looking for an algorithm. |
Hello everyone,
I am looking for a fast algorithm which enumerates 16-bit integers, sorted by the number of bits that are set. I have come up with one of my own, but I am wondering if there is a faster, better way of doing this. Ideally, the numbers with the same number of set bits should be sorted (ascending or descending), but that isn't a must. Simplified to 4 bits, the output sequence could look like this: 1111b, 0111b, 1011b, 1101b, 1110b, 0011b, 0101b, 0110b, 1001b, 1010b, 1100b, 0001b, 0010b, 0100b, 1000b, 0000b |