I do know how to do it on paper. The problem is when i do it on code. I get this error:
incompatible types: possible lossy conversion from int to byte
I know my binary number is getting saved in a String and i want to change those 0's to 1's and viceverse which is why i have the if
here's my code:
import java.util.Scanner:
Public class decimalacomplemento1 {
public static void main(String[] ar){
Scanner decimal = new Scanner(System.in);
int dividendo, base = 2, numero, resto;
String binario = "";
System.out.println("Ingrese numero");
numero = decimal.nextInt();
dividendo = numero;
while(dividendo >= base){
resto = dividendo % base;
binario = resto + binario;
dividendo = dividendo/base;
}
binario = dividendo + binario; // el numero binario
if (binario == 0) {
binario = 1;
}else{
binario = 0;
}
System.out.println("En sistema binario " + numero + " se escribe " + binario);
}
}