R Ry Beta member Messages 5 May 2, 2005 #1 Does anybody know how to generate all combinations of 1's and 0's in ten bits in java. like this: 0000000000 0000000001 0000000010 ...ect,ect..up to 1111111111 Any help is appreciated, thanks.
Does anybody know how to generate all combinations of 1's and 0's in ten bits in java. like this: 0000000000 0000000001 0000000010 ...ect,ect..up to 1111111111 Any help is appreciated, thanks.
E Emily Daemon Poster Messages 1,179 May 2, 2005 #2 Off the top of my head the only way I can think of to do it is to use 10 nested for loops. Pseudocode: Code: for (ten=0;ten<=1;ten++) { for (nine=0;nine<=1;nine++) { for (eight=0;eight<=1;eight++) } . . . for (one=0;one<=1;one++) { // print vars ten, nine, eight, seven, six, five, four, three, two, one } } } } } } } } } } Hope this helped.
Off the top of my head the only way I can think of to do it is to use 10 nested for loops. Pseudocode: Code: for (ten=0;ten<=1;ten++) { for (nine=0;nine<=1;nine++) { for (eight=0;eight<=1;eight++) } . . . for (one=0;one<=1;one++) { // print vars ten, nine, eight, seven, six, five, four, three, two, one } } } } } } } } } } Hope this helped.