![]() |
VOOZH | about |
Given a non-negative number n. The problem is to unset the last m bits in the binary representation of n.
Constraint: 1 <= m <= num, where num is the number of bits in the binary representation of n.
Examples:
Input : n = 10, m = 2 Output : 8 (10)10 = (1010)2 (8)10 = (1000)2 The last two bits in the binary representation of 10 have been unset. Input : n = 150, m = 4 Output : 144
Approach: Following are the steps:
Note: The sizeof(int) has been used as input is of int data type. For large inputs you can use long int or long long int datatypes in place of int.
Output:
144
Time Complexity: O(1)
Auxiliary Space: O(1)