Given N as the number of bits and K as the Number of 1s, how can i generate all binary representations that contain K ones and N-k zeros?
in other words i have:
N=4 //number of bits
K=2 //number of ones
All possible binary values containing N bits,K ones and N-K zeros are:
1100
1010
1001
0110
0101
0011
i have nothing so far. i am not asking for code. i am just asking for the best way to do it? an algorithm? a pseudocode? maybe a discussion?
Edit: I am asking for code/pseudocode to solve the problem... and not a math formula...