Ive written a program for converting binary to decimal, however I was wondering how can I do it without using Math.pow ( ) and by only using methods charAt ( ) and length()
thank you,, any help would be appreciated
public class BinaryToDecimal{
public static void main(String[] args){
String binaryString = args[0];
int decimalValue;
int length = binaryString.length();
double j = 0;
for (int i=0; i< binaryString.length(); i++){
if (binaryString.charAt(i)== '1'){
j = j+ Math.pow(2, binaryString.length() - 1 - i);
}
}
decimalValue = (int) j;
System.out.println(decimalValue);
}
}