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.
Displaying bits? Or turning a text representation of a binary number into an integers (use strtoul).
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.
Minor mod to the code from the first link (well, if you followed on to Part 2).
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;
unsigned int i;
for ( i = 0; i < sizeof Binary / sizeof *Binary; ++i )
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.