What I want to know is how many numbers can be set if N bits are set to 1 out of 32bits.
Example lets try with 4 bits
//HowMany(1) = 4
//1000
//0100
//0010
//0001
//
//HowMany(2) = 6
//1001
//1010
//1100
//0110
//0101
//0011
public int HowMany(int bits)
{
....
}
I am trying to compute a precompute a dictionary for this but it takes ages:
var dict = new Dictionary<int, int>();
for (int i = 0; i <= Int32.MaxValue; i++)
{
var str = Convert.ToString(i, 2);
var count = str.Count(x => x == '1');
if (!dict .ContainsKey(count))
dict .Add(count, 0);
dict [count] += 1;
}