Overwriting a range of bits in an integer in a generic way
- by porgarmingduod
Given two integers X and Y, I want to overwrite bits at position P to P+N.
Example:
int x = 0xAAAA; // 0b1010101010101010
int y = 0x0C30; // 0b0000110000110000
int result = 0xAC3A; // 0b1010110000111010
Does this procedure have a name?
If I have masks, the operation is easy enough:
int mask_x = 0xF00F; // 0b1111000000001111
int…