1276. Turn Off the Rightmost Set Bit

EasyBit ManipulationBit ManipulationLowest Set BitBit Trick

Given a non-negative integer n, return the value obtained by turning off (clearing) its rightmost set bit. If n is 0 there is nothing to clear, so return 0.

Input: A JSON object {"n": <non-negative integer>}.

Output: Return n with its lowest set bit cleared.

Examples

Example 1
Input: {"n":12}
Output: 8
Explanation: 1100 & 1011 = 1000 = 8.
Example 2
Input: {"n":7}
Output: 6
Explanation: 0111 & 0110 = 0110 = 6.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →