I have the following code for a recursive function to convert binary to int:
public static int binaryToInt( String b ) {
if(b.length() < 2) {
return 0;
}
return b.charAt(0) * (int) Math.pow(2, b.length()) + binaryToInt(b.substring(1));
}
I am not getting the correct values for example: "101" I get 584. I thought my logic is correct but can someone please point out where i am going wrong?