Skip to content

Incorrect Code Example for "Set kth Bit" in Binary Section #677

Open
@roemvaar

Description

@roemvaar

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions