Something like that...? Can probably be optimized better.
Edited by patrrr, 17 October 2012 - 06:33 AM.
Posted 17 October 2012 - 06:20 AM
unsigned copy_bit(unsigned x, int i, unsigned y, int j) {
y &= ~(1u << j); // Clear y's j-th bit
y |= ((x >> i) & 1u) << j; // Copy x's i-th bit into position j
return y;
}