# Subsets of binary string

• 05-03-2005
damonbrinkley
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.
• 05-03-2005
Dave_Sinkula
Displaying bits? Or turning a text representation of a binary number into an integers (use strtoul).
• 05-03-2005
damonbrinkley
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.
• 05-03-2005
Dave_Sinkula
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; }```
• 05-03-2005
damonbrinkley
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.