add bit_manipulation: add parity, next_power_of_two, rotate_bits codes - #13157
Merged
cclauss merged 4 commits intoSep 13, 2026
Merged
Conversation
… Basuki Nath) and extend doctests
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| """ | ||
|
|
||
|
|
||
| def next_power_of_two(n: int) -> int: |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: n
| """ | ||
|
|
||
|
|
||
| def rotate_left32(x: int, k: int) -> int: |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: x
Please provide descriptive name for the parameter: k
| return ((x << k) & mask) | ((x & mask) >> (32 - k)) | ||
|
|
||
|
|
||
| def rotate_right32(x: int, k: int) -> int: |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: x
Please provide descriptive name for the parameter: k
cclauss
approved these changes
Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added three small, self-contained bit-manipulation utilities and extended doctests for two existing files. New files include author metadata (Author: Basuki Nath).
Changes are minimal, follow repository contribution rules (doctests, small functions, no external deps), and are intended as low-effort additions suitable for first-time contributors.
Files changed
Added:
Added:
parity.py - parity(number) returns 1 for odd parity, 0 for even parity.
next_power_of_two.py - next_power_of_two(n) returns smallest power of two >= n for positive integers.
rotate_bits.py- rotate_left32(x, k) and rotate_right32(x, k) for 32-bit rotations.
Modified:
is_power_of_two.py - added extra doctest examples (edge cases).
count_number_of_one_bits.py- added extra doctest examples (additional cases).