1268. Clear the Nth Bit of a Number

EasyBit ManipulationBit ManipulationBit MaskingAND

Given an integer n and a 0-indexed bit position k, return the value obtained by clearing the k-th bit of n (forcing it to 0). If the bit is already 0, n is unchanged.

Input: A JSON object {"n": <integer>, "k": <bit index>} with 0 <= k <= 40.

Output: Return the integer n with bit k forced to 0.

Examples

Example 1
Input: {"n":5,"k":0}
Output: 4
Explanation: 101 & ...1110 = 100 = 4.
Example 2
Input: {"n":15,"k":1}
Output: 13
Explanation: 1111 & ...1101 = 1101 = 13.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →