![]() |
VOOZH | about |
Given an integer N, the task is to print the number obtained by unsetting the least significant K bits from N.
Examples:
Input: N = 200, K=5
Output: 192
Explanation:
(200)10 = (11001000)2
Unsetting least significant K(= 5) bits from the above binary representation, the new number obtained is (11000000)2 = (192)10Input: N = 730, K = 3
Output: 720
Approach: Follow the steps below to solve the problem:
mask = ((~0) << K + 1) or
mask = (-1 << K + 1)
Below is the implementation of the above approach:
720
Time Complexity: O(1)
Auxiliary Space: O(1)