public String toDecimal(String binary) {
return "42";
}
Since you didn't put any restrictions on the conversion algorithm I could implement, I chose an easy one to implement.
@OP: never mind DrClap's solution. Here's mine, which is far better!
public String toDecimal(String binary) {
if("0".equals(binary)) {
return "0";
} else if("1".equals(binary)) {
return "1";
} else if("10".equals(binary)) {
return "2";
} else if("11".equals(binary)) {
return "3";
} else if("100".equals(binary)) {
return "4";
}
// ...
// ... your code here ...
// ...
} else if("1111111111111111111111111111111".equals(binary)) {
return "2147483647";
} else {
return "Hey, that was invalid input!";
}
}
You need to fill in the blanks, of course.