public class goofy {
public static void main(String[] args){
System.out.print(toInt("101"));
}
public static int toInt(String Bin){
int ans = 0;
for(int i=0;i<Bin.length();i++){
ans = ans+(int)((int)Bin.charAt(i)*Math.pow(2,Bin.length()-i));
}
return ans;
}
}
This is my code, I named it goofy becaus eit acts goofy:) can anyone tell me why this is not working when I try to convert binary(Bin) into decimal?
running the code I expect it to print the decimal integer