Métodos
estáticos pata operaciones básicas de dos números binarios.
Reciben los dos números y retorna el resultado.
public static String Suma(String a, String b) {
int a1 = Integer.parseInt(a, 2);
int b1 = Integer.parseInt(b, 2);
int c1 = a1 + b1;
String resultado = Integer.toString(c1, 2);
return resultado;
}
public static String Resta(String a, String b) {
int a1 = Integer.parseInt(a, 2);
int b1 = Integer.parseInt(b, 2);
int c1 = a1 - b1;
String resultado = Integer.toString(c1, 2);
return resultado;
}
public static String Divicion(String a, String b) {
int a1 = Integer.parseInt(a, 2);
int b1 = Integer.parseInt(b, 2);
int c1 = a1 / b1;
String resultado = Integer.toString(c1, 2);
return resultado;
}
public static String Multiplicacion(String a, String b) {
int a1 = Integer.parseInt(a, 2);
int b1 = Integer.parseInt(b, 2);
int c1 = a1 * b1;
String resultado = Integer.toString(c1, 2);
return resultado;
}
amigo, porque en String resultado = Integer.toString(c1, 2);
ResponderEliminarpones un 2 al final,?
por base 2?
Aquí puedes ver más operaciones
Eliminarhttp://desarrollox2.blogspot.com/2013/05/calculadora-binaria-en-java.html
Si, es la base, puede ser base 8 por ejemplo o base 16
ResponderEliminarInteger.parseInt(a, 8);
Integer.parseInt(a, 16);
ayuda como puedo sumar restar multiplicar y dividir numero de base 2,3,4,5,6,7,8,9 en netbeans por favor necesito urgente
ResponderEliminarcambia la base Integer.parseInt(a, base);
EliminarInteger.parseInt(a, 8) base 8
Integer.parseInt(a, 7) base 7
etc
un favor amigo me lo pude hacer necesito urgente le pago
Eliminarejemplo de 2345 en base 6 + 3453 en base 6 el resultado tiene que ser en base 6 también lo mismo en la resta multiplicación y división por favor en el lenguaje de java (netbeans)
EliminarComo puedo sumar restar multipicar y dividir en hexadecimal en java netbeans
ResponderEliminaralguna sugerencia, para hacer lo mismo pero en matlab?
ResponderEliminar