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
Can anybody please help me in solving this question?
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
Can anybody please help me in solving this question?
Sure - where are you stuck? Please post the code you have so far (be sure to use code tags).
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.
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?
Last edited by Adak; 08-24-2012 at 11:13 AM.
Good start. Now, with respect to this assignment, how many different values should each of those variables be able to hold?I selected 6 variables for 6 bits.
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.
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.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.
Adak... the object of this question is to generate truth table using nested for() 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.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.
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.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.
Last edited by Matticus; 08-24-2012 at 11:26 AM. Reason: Tried to clarify my statement
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.