generate all combinations

Status
Not open for further replies.

Ry

Beta member
Messages
5
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.
 
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. :confused:
 
Status
Not open for further replies.
Back
Top Bottom