Uh, why not just xor with all ones? Why use an array of integers at all? That's an incredible waste of space -- to use an entire integer to contain a 1 or 0.
Also, why are you making comparisons to characters? '1' and '0' are characters. This would make sense if your int array, "binary", is actually an array of characters, but that's not how it's declared.
Next issue: Why is your function called "toDecimal" if what you're really doing is taking the bit inverse? It's misleading.
And what the heck does your "weight" variable have to do with anything? Multiplying by two is the same as shifting a binary number to the left once. Why not use a bit shifting operation instead of multiplication?
Why not just multiply your running sum by 2 each iteration, instead of figuring out just one bit, multiplying that by the appropriate power of 2, then adding it to the running sum?
Let me rephrase the above using code:
int num = 0;
for (count = 0; count < SIZE; ++count)
{
num *= 2; // shift left.
num += (binary[count] == '1')? 0 : 1
}
Isn't that easier than dealing with three different variables?
Take care,
Nik
http://www.bigaction.org/