Hello all:(adsbygoogle = window.adsbygoogle || []).push({});

I need to write a program that takes an array of 0's and 1's and converts them into base 10 numbers. Here is my code, but I cant get it to return the correct base 10 number.

Any help is appreciated.Code (Text):/* This program returns a value in base 10 from an array of binary numbers.

*

*/

public class binary

{

public int convertBaseTen( int [] a) // method takes an array

{

int numValue=1;

int sum=0;

for(int i = 0; i< a.length; i++) // loop through array a

{

if (a[i]==1)

{

sum+=numValue;

}

numValue*=2;

}

return numValue;

}

}

Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Java Program Help

**Physics Forums | Science Articles, Homework Help, Discussion**