November 16th, 2011, 02:57 PM
Search of a boolean array
Hi, I've been struggling for this problem for a fairly long time. Pretty much, I'm looking for a way to generate every possible boolean array of size n (so 2^n arrays) so that I can perform a test on each one. Obviously I could do this with loops, but that takes a while to code.
Thanks for the help.
November 16th, 2011, 04:52 PM
Re: Search of a boolean array
You just have to generate every integer between 0 and 2^n - 1. The bit-pattern of each integer will constitute one unique boolean "array".
Say n=3. The integers are 0, 1, 2, 3, 4 ,5, 6 and 7. And the corresponding boolean "arrays" are 000, 001, 010, 011, 100, 101, 110 and 111 respectively. You get at the individual bits by using bitwise integer operations.
Last edited by nuzzle; November 17th, 2011 at 05:58 AM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!