Generate all possible 5-bit binary combinations

Solved
Maxxx -  
 Maxxx -
Hello, I would like to write a program to generate all the combinations of size five in binary
example:
00000
00001
00010
00011
00100
00101
00110
00111
...
11111

But I don't know exactly how to go about it, at first I wanted to use a tree structure but I'm not very good at that. Do you have a simpler idea (with an array for example) to do this?
Thank you in advance.

1 réponse

yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 588
 
Hello, in what context are you doing this?
0
Maxxx
 
Hello, I would like to generate all the combinations to then find the one that will allow me to decipher a binary sequence; it's cryptography. But I can't seem to generate all possible combinations.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > Maxxx
 
Two lines of thought for improvement:
1) Did you know that these binary combinations can be used to represent numbers? Can you write the decimal representations of each binary number on your list?
2) How would you go about generating all the combinations of 3 decimal digits?
0
Maxxx > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
1) Each binary number represents a decimal number in the usual order, which means that:
00000=> 0
00001 => 1
00010 =>2
00011 =>3
00100 =>4
...
11111=>(2^5)-1=31

2) I know that we need to start from 100 and stop at 999, but I don't see how, among all decimal digits, we can select only those with 3 digits.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > Maxxx
 
1) Doesn't that give you an idea for obtaining these combinations?

2) Aren't you forgetting the number 0?
0
Maxxx > yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention  
 
Well, I finally managed to do it by taking the decimal number each time, I store the remainder using %2 and I divide my number by two. This gives me all the combinations and by using some restrictions I get the one I want. Thank you very much for your help, have a nice day.
0