-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilidades.java
More file actions
38 lines (33 loc) · 876 Bytes
/
Utilidades.java
File metadata and controls
38 lines (33 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Clase con métodos útiles para la ejecución del algoritmo
*
* @author isma
* @version 1
*/
public class Utilidades {
public Utilidades() {
}
public static double generarAleatorio() {
return new java.util.Random().nextDouble();
}
public static int obtenerLongitud(double limiteInferior, double limiteSuperior, int tolerancia) {
double resta = limiteSuperior - limiteInferior;
double division = resta / Math.pow(10, tolerancia * (-1));
double suma = 1 + division;
double logaritmo = Math.log10(suma) / Math.log10(2);
int redondeo = (int) Math.rint(logaritmo) + 1;
return redondeo;
}
public static int toIntValue(boolean[] array) {
int decimalValue = 0;
int exp = 0;
int index = array.length - 1;
while (index >= 0) {
if (array[index])
decimalValue += Math.pow(2, exp);
exp++;
index--;
}
return decimalValue;
}
}