1277. Isolate the Rightmost Set Bit

EasyBit ManipulationBit ManipulationLowest Set BitBit Trick

Given a non-negative integer n, return a value that has only the rightmost set bit of n set and all other bits cleared. If n is 0, return 0.

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

Output: Return the isolated lowest set bit of n (a power of two, or 0).

Examples

Example 1
Input: {"n":12}
Output: 4
Explanation: 12 & -12 = 4 (the lowest set bit).
Example 2
Input: {"n":18}
Output: 2
Explanation: 18 & -18 = 2.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →