Created
December 4, 2015 05:06
-
-
Save VFS/4a4b85ec4902fcfc0ba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gera todas as entradas possíveis par as N entradas existentes. | |
private boolean[] parse(int i, int N) { | |
//i = 0 - iteração | |
//N = 3 - quantidade de entradas possíves | |
// i=0 -> [0,0,0] | |
// i=1 -> [0,0,1] | |
// ... | |
// i=5 -> [1,0,1] | |
boolean b[] = new boolean[N]; | |
// conversão para um array de booleans representando em binário | |
for(int j=N-1; j>=0; j--){ | |
if (i>= Math.pow(2, j) ){ | |
b[N-j-1]=true; | |
i -= Math.pow(2, j); | |
}else{ | |
b[N-j-1]=false; | |
} | |
} | |
//System.out.println(Arrays.toString(b)); | |
//System.out.println("\ni = "+i+"\n\n"); | |
//System.out.println("N = "+N+"\n\n"); | |
return b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment