updateBit(n: number, k: number, value: number | boolean): number
Updates the bit at the specified position with the given value.
This function updates the bit at the kth position to either 1 or 0 depending on the provided value.
If the value is a boolean, it will be normalized to 1 (true) or 0 (false).
Returns
The new number with the bit at position k updated.
Parameters
n: number
The number in which the bit will be updated.
k: number
The position of the bit to update (0-indexed).
value: number | boolean
The value to set the bit to (1 or 0, or true/false).
Updates the bit at the specified position with the given value.
This function updates the bit at the
k
th position to either1
or0
depending on the provided value. If the value is a boolean, it will be normalized to1
(true) or0
(false).Returns
The new number with the bit at position
k
updated.