Insert a Pattern of Ones Into a 32-bit Integer
Problem
Given a 32-bit integer, set (insert) a contiguous pattern of ones between bit positions i and j inclusive, using bit masks (avoid loops where possible).
Example
n=0b1000, set bits [1..2] -> 0b1110
Constraints
- 0 ≤ i ≤ j ≤ 31
added …