I got the following code:
public class decToBin {
public static void main(String args[]) {
int number = 32;
System.out.println(decToBinWrapper(number));
}
public static String decToBinWrapper(int number) {
return decToBin(number, "");
}
public static String decToBin(int number, String bin) {
if (number >= 1)
return decToBin(number / 2, bin + Integer.toString(number % 2));
else
return "0";
}
}
which is supposed to convert a decimal to binary but it only prints "0" instead of the binary string. Could someone tell me what I'm doing wrong please?
numberis already binary.