Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class test {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. // Get bit sequence length
  6. int n = 3;
  7.  
  8. // Get maximum number
  9. int max = (int)Math.pow(2, n);
  10.  
  11. for (int i = 0; i < max; i++) {
  12.  
  13. // We want the leading zeros in this case so we replace whitespace with zeros
  14. String s = String.format("%16s", Integer.toBinaryString(i)).replace(' ', '0');
  15.  
  16. // Comment this out
  17. System.out.print("#"+i+": ");
  18.  
  19. // We only want the length of n so we'll grab the first n numbers
  20. // and remove the excess zeros
  21. System.out.println(s.substring(s.length() - n));
  22.  
  23. }
  24.  
  25. }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement