# Thread: Generate Possible combination of 6-bit Binary number

1. ## Generate Possible combination of 6-bit Binary number

Using C-Programming nested for() loops, write a program that displays all
possible combinations of a 6 bit binary number.

Sample Run: 000000, 000001, 000010, 000011, ...........111110, 111111

2. Sure - where are you stuck? Please post the code you have so far (be sure to use code tags).

3. i did a bit paper work. But didnt find any solution. I am facing problem in choosing termination condition for for() loop. I selected 6 variables for 6 bits.

4. Originally Posted by Azeem
Using C-Programming nested for() loops, write a program that displays all
possible combinations of a 6 bit binary number.

Sample Run: 000000, 000001, 000010, 000011, ...........111110, 111111

Looking at the sample binary numbers you posted, do you see a certain incrementing pattern?

And btw, although it's used incorrectly most times, I refer to the above as permutations, not combinations.

Combinations are like a group sitting around a conference table - it doesn't matter what chair you sit in, only that each person is at the table. (And a permutation IS what you have with a combination bike lock, where 1-1-1-1 could be a perfectly good combination.

It may help to think in very simple terms: if you had two such numbers to work with like this, again using nested loops, how would you proceed?

5. I selected 6 variables for 6 bits.
Good start. Now, with respect to this assignment, how many different values should each of those variables be able to hold?

6. Hint, find the highest number that is possible to represent with 6 bits. This number is the terminating condition in your loop, print all numbers up to and including that number, and that will be all possible combinations. Now you just need to figure out how to print a number in binary.

7. Hint, find the highest number that is possible to represent with 6 bits. This number is the terminating condition in your loop, printing all numbers up to and including that number will be all combinations. Now you just need to figure out how to print a number in binary.
I'm assuming, based on the wording of the assignment, that having six distinct variables (as the OP has done) is the way to go - your solution would be cleaner, but wouldn't require nested "for()" loops in the way that I suspect is required.

8. Adak... the object of this question is to generate truth table using nested for() loop.

9. Originally Posted by Matticus
I'm assuming, based on the wording of the assignment, that having six distinct variables (as the OP has done) is the way to go - your solution would be cleaner, but wouldn't require nested "for()" loops in the way that I suspect is required.
It depends, if the "print binary" part is using a loop, then it would work. As a side note, it's a bit odd to require a nested loop imo.

10. Originally Posted by Matticus
Good start. Now, with respect to this assignment, how many different values should each of those variables be able to hold?
ok. variables should hold '0' & '1' as the program is for printing binary numbers. Possible combinations are 64 for 6 bit number. This means outer loop terminates at 64.

11. It depends, if the "print binary" part is using a loop, then it would work. As a side note, it's a bit odd to require a nested loop.
While you're technically correct, I interpret the assignment to use nested "for()" loops with distinct variables for each bit. However, the description of the assignment is vague, so I could very well be off.

And btw, although it's used incorrectly most times, I refer to the above as permutations, not combinations.
I don't see this as permutations (different arrangements of the elements) or combinations (different subsets of the elements). It's simply counting.

13. ok. variables should hold '0' & '1' as the program is for printing binary numbers. Possible combinations are 64 for 6 bit number. This means outer loop terminates at 64.
Ah, but if your variables should hold either 0 or 1, then none of them should ever be 64. Again, if I understand correctly, while you're printing out binary numbers, it doesn't necessarily mean they are represented as full numbers in your code.

14. Does it really matter how you represent your number(s) or even if you do? From what's said it does not seem that way..

write a program that displays all
possible combinations of a 6 bit binary number.

15. Originally Posted by Matticus
Ah, but if your variables should hold either 0 or 1, then none of them should ever be 64. Again, if I understand correctly, while you're printing out binary numbers, it doesn't necessarily mean they are represented as binary numbers (strings of 0's and 1's) in your code.
i selected 6 variables for 6 bits and 1 variable to control outer loop which initializes with 1 and terminates at 64. This outer loop is to generate rows.