I am trying to create a loop that will go through all different integers, where exactly 10 of the last 40 bits are set high, the rest are set to low. The reason is because I have a map with 40 different values, and I want to summarize all the different ways so that ten of these values can be multiplied. (This is just out of curiosity, so this is really a “bitmanip” loop of interest, not the amount as such.)
If I did this, for example, 2 out of 4 bits, it would be easy to set everything manually,
0011 = 3, 0101 = 5, 1001 = 9, 0110 = 6, 1010 = 10, 1100 = 12,
but with 10 out of 40, I can’t find a way to create them effectively. I tried starting at 1023 (= 1111111111 in binary), finding a good way to manipulate this, but without success. I tried to do this in C ++, but this is really a general method (if any) that is of interest. I made some kind of search engine, but with little success, if anyone has a good link, this, of course, will be appreciated. :)
source share