Open
Description
In the Binary Techniques section of the repository, the code example for "Set kth Bit" contains an error. The current code is written as:
num |= (1 >> k);
However, this implementation is incorrect. The correct code should be:
num |= (1 << k);
Issue:
The bit-shift operator is incorrectly specified as >> (right shift) instead of << (left shift). Using >> will shift bits to the right, which does not align with the intended functionality of setting the kth bit. To set the kth bit, we need to shift the bit 1 to the left by k positions.
Expected Behavior:
The code should correctly set the kth bit of the given number num by performing a left shift operation (1 << k) and then using the bitwise OR operator (|=).
Metadata
Metadata
Assignees
Labels
No labels