I have a function where the input and output are bool arrays (longer than the simple example). Internally the function works on fixed length integers (i.e. integers that are exactly 12 bits or 7 bits, ...). So the first step is to convert the input bool array into an equivalent int array. Here's an example :
bool bits[10*12];
unsigned int ints[10];
for(int k=0;k<10;k++)
{
x=1;
t=0;
for(int b=0;b<12;b++)
{
t+=x*bits[k*12+b];
x*=2;
}
ints[k]=t;
}
which converts an input array of 120 bits to an int array with 10 entries, each being 12 bits. This works fine but I'd like to see if there are more efficient ways of doing this.
bools, @DrewDormannstd::bitsetinstead of rolling your own. It's hard to be completely sure if it's what you need given that we don't know the reason why you're doing this. en.cppreference.com/w/cpp/utility/bitset