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<=stop_index;id++){
result+=b_array[id] * pow(2.0,run);
run++;
}
return result;
}
but it doesnt this work?
Thanks and kind regards Nic
{ false, true, true, false}into0b0110= 6? Then you should use better casting, so(int)b_array[id]and(int)pow(2.0,run). Though it's a weird way to do it, since bitshifting would be more appropriate (result += b_array[id] ? (1 << run) : 0) . Also be aware of the numerical limits of your 16-bit signedint.