I would like to avoid the if statement below. Can I somehow copy the set bits from the old bit array to the new one using only bitwise operators?
#define BYTE_POS(pos) (pos / CHAR_BIT)
#define BIT_POS(pos) (1 << (CHAR_BIT - 1 - (pos % CHAR_BIT)))
if ((old_array[BYTE_POS(old_pos)] & BIT_POS(old_pos)) != 0) {
new_array[BYTE_POS(new_pos)] |= BIT_POS(new_pos);
}
Change BIT_POS to this:
then change the code to: