C: Convert int array representing bits of a number into a single Int?

arrays, c, integer

Solution

You basiclly have the answer but you would be better doing it from the other direction ie:

int multiplier = 1;
for (i = 7; i >= 0; --i )
{
    bin += (multiplier * arrbin[i]);
    multiplier *= 10;
}

that way you can change the length of the array you are using easily.

Problem

I am a beginner in C and wish to know how to convert an array of numbers that represent the bits of a number into the integer it represents. I searched online but only found char array to int. I am making converter and need to int array to toggle the bit values from 1 to 0 and vice versa(ie binary). So far i have managed to make the array integers toggle, but I cannot figure out how to change the array of numbers into the single number the array represents. I need this integer so i can convert it into a decimal number which the user can view. Is there any simple solution to this? bin= integer variable to store the binary number arrbin = integer array to store the state of the bit ie(00000000) ``` for (i = 0; i < 8; ++i ) { bin = bin + (10 * arrbin[i]); } ``` EDIT: I think i see the problem now, instead of the values being implemented every exponent of 10 up, the numbers were only being multiplied by 10. will try and see if this fixes it. EDIT #2: I dont mean conversion of binary to decimal. I meant conversion of array of numbers ie{1,0,0,0,0,0,0,1) to integer (integer varible = 10000001 not 129)

Original source