I am trying to convert a
string binary value to it's decimal value. the code I have below keeps on generating a zero (0) every time I run the application? I can go through my logic on paper and get the correct value, but I am at the end of my rope on why my code is not generating the correct result. Any suggestions would be of great help! Thank you in advance !!!
Here is my code:
private int BTD(int n, String bin)
{
int result = 0;
for (int i=0; i<bin.length(); i++)
{
result = (result * 2) + (bin.charAt(i)-'0');
}
return result;
}