For given n inputs, I need to generate all possible input combinations using C++
eg. n =4
I need to get,
1010101010101010
1100110011001100
1111000011110000
1111111100000000
(EDIT : In case this is not clear, these are the input combinations read column-wise)
I need these to perform operations like & and | so it would be best if I get them in their integer representation as n different variables.
I tried doing it using bitset for 32 input combinations but it took a long time to process. I was hoping if you guys had any ideas on a better implementation?
EDIT : Example when n=3
10101010
11001100
11110000
Your question doesn't make that much sense but hopefully this is somewhat to what your looking for:
So n is your n as you said, total is the total number of possibilities that can be held in n (3) bits. Then a char array is setup, you can use int if this is too short. All possibles are added. This is because a truth tables possibilities are the same as that of what can be in those many bits.
The second printf shows an AND operation, here we would be doing e.g.:
See Alfs code for formatting in the way you want (especially in binary not in decimal like this)
n=4 would be
not what you generated (not sure what you mean by "n")???
Your question is still utterly incomprehensible to me.
The code below, however, reproduces your example output.
Now I hope this wasn't homework. If it was then you're deceiving yourself and others by seeking answers on SO (which will bite you, and others, later). For homework, please indicate clearly that it is homework, then we can adjust our answers correspondingly.
Cheers & hth.,
Here is a short implementation that generates that output: