i need to set bits from o to k
let say we have 10101 and i need to set till 2 means
i need a mask like 00111 and then or till the given number so how can i create this mask???
Given a number, set bits from 0 to Kth position. Do it in O(1) time
To set any bit we use bitwise OR | operator. As we already know bitwise OR | operator evaluates each bit of the result to 1 if any of the operand’s corresponding bit is set (1). In-order to set kth bit of a number we need to shift 1 k times to its left and then perform bitwise OR operation with the number and result of left shift performed just before.
@hey i got ur point my question is not shift the 1 bit…
I have to set range of bits from 0 to k
example N = 10101 k = 2; then the ans = 10111 i have to in constant time