Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class test {
- public static void main(String[] args) {
- // Get bit sequence length
- int n = 3;
- // Get maximum number
- int max = (int)Math.pow(2, n);
- for (int i = 0; i < max; i++) {
- // We want the leading zeros in this case so we replace whitespace with zeros
- String s = String.format("%16s", Integer.toBinaryString(i)).replace(' ', '0');
- // Comment this out
- System.out.print("#"+i+": ");
- // We only want the length of n so we'll grab the first n numbers
- // and remove the excess zeros
- System.out.println(s.substring(s.length() - n));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement