Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roemvaar opened this issue Nov 30, 2024 · 0 comments · May be fixed by #678
Open

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

roemvaar opened this issue Nov 30, 2024 · 0 comments · May be fixed by #678

Comments

@roemvaar
Copy link

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 (|=).

@roemvaar roemvaar linked a pull request Nov 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant