Skip to content

Instantly share code, notes, and snippets.

@VFS
Created December 4, 2015 05:06
Show Gist options
  • Save VFS/4a4b85ec4902fcfc0ba2 to your computer and use it in GitHub Desktop.
Save VFS/4a4b85ec4902fcfc0ba2 to your computer and use it in GitHub Desktop.
// 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