Need function to convert bool array to int- why doesnt this work? Hey I wrote this function to convert an bool array to int:
(Math Lob included):

bool b_array[5];

int convertToInt(start_index,stop_index){
    int run=0;
    int result=0;
    for(int id=start_index;id&lt;=stop_index;id++){
        result+=b_array[id] * pow(2.0,run);
        run++;
    }
    return result;
} 


but it doesnt this work?

Thanks and kind regards 
Nic
Assuming little-endian bools (least significant bool first), you should use simple bit-shifting, not floating point power calculations:

for(int id=start_index;id&lt;=stop_index;id++){
    result |= b_array[id] ? (1 &lt;&lt; run) : 0;
    run++;
}


The ternary operation (b_array[id] ? (1 &lt;&lt; run) : 0) means:


If b_array[id] is true,  then


Or result with 1 left-shifted run times and store in result

otherwise


Or result with 0 and store the result (no-operation).