Clear a Specified Bit

Given a non-negative integer n and a zero-based bit position bitIndex, clear that bit to 0 and return the resulting integer. Position 0 is the least…

Given a non-negative integer `n` and a zero-based bit position `bitIndex`, clear that bit to `0` and return the resulting integer. Position `0` is the least significant bit. Every other bit must stay unchanged.

- `0 <= n <= 2,147,483,647` - `0 <= bitIndex <= 30` - Return the resulting value as an integer.

Example 1: input n = 13, bitIndex = 0; output 12. 13 is 1101₂. Position 0 is the rightmost bit, so clearing it gives 1100₂, which is 12.

Example 2: input n = 13, bitIndex = 1; output 13. Position 1 already contains 0, so clearing it leaves the number unchanged.

Example 3: input n = 13, bitIndex = 2; output 9. Position 2 contains 1. Clearing only that bit changes 1101₂ to 1001₂, which is 9.

Category: Math & Numbers. Topic: math. Difficulty: Easy. Patterns: bit-manipulation.