Generate all possible 5-bit binary combinations
Solved
Maxxx
-
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.
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?
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?
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.
2) Aren't you forgetting the number 0?