Turn On Bits From Position i to j (No Loop)

Problem Set all bits between positions i and j (inclusive) to 1 in a 32-bit integer, without using a loop.

Input / Output

  • Input: integer n, positions i and j.
  • Output: n with bits i..j set to 1.

Constraints

  • 0 ≤ i ≤ j ≤ 31.
  • No loops — bit manipulation only.

Example

  • n=0, i=2, j=5 → 0b111100
added …
LeaderboardSalaryAccount