00101
=5 位,忽略两个零并计算
0+(5-2-1)^2 = 4
4+(5-3-1)^2 = 5
5+(5-4-1)^2 = 5
最终答案是否正确?
char[] charArray = binary.toCharArray();
double answer = 0;
for (double index = 0; index < charArray.length; index++)
{
if (charArray[(int)index] == '1')
{
answer = answer + Math.pow(2.0, (charArray.length - index - 1));
}
}