Search of a boolean array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Search of a boolean array

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    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.

  2. #2
    Join Date
    May 2009
    Posts
    2,413

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center