Subsets of binary string

This is a discussion on Subsets of binary string within the C Programming forums, part of the General Programming Boards category; Hello everyone. I am working on a program in which part of it I need to generate all subsets of ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    385

    Subsets of binary string

    Hello everyone. I am working on a program in which part of it I need to generate all subsets of a 10-bit binary string. So, I need to iterate through:

    0000000001 - 1
    0000000010 - 2
    0000000011 - 3
    .
    .
    .
    1111111111 - 1023


    Can anyone just help me a bit on some theoretical ways to go about this? For some reason I can't get my head around where to start.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Displaying bits? Or turning a text representation of a binary number into an integers (use strtoul).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    I want to generate all possible combinations of a 10-bit binary sequence and put each into an array of strings that would be of size 1024.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Minor mod to the code from the first link (well, if you followed on to Part 2).
    Code:
    #include <stdio.h>
    
    char *bits_myuint(char *dest, unsigned int value)
    {
       char *start = dest;
       unsigned int bit;
       for ( bit = 0x200; bit > 0; bit >>= 1 )
       {
          *dest++ = value & bit ? '1' : '0';
       }
       *dest = 0;
       return start;
    }
    
    char Binary[1024][11];
    
    int main()
    {
       unsigned int i;
       for ( i = 0; i < sizeof Binary / sizeof *Binary; ++i )
       {
          puts(bits_myuint(Binary[i], i));
       }
       return 0;
    }
    Last edited by Dave_Sinkula; 05-03-2005 at 08:57 AM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    Wow, thanks Dave. Now it's time for me to study and understand that code before I consider putting it into my code. Greatly appreciated.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21