Skip to content

add bit_manipulation: add parity, next_power_of_two, rotate_bits codes - #13157

Merged
cclauss merged 4 commits into
TheAlgorithms:masterfrom
basukinath:feature/add-bit-examples-basuki
Sep 13, 2026
Merged

cclauss merged 4 commits into
TheAlgorithms:masterfrom
basukinath:feature/add-bit-examples-basuki

Conversation

@basukinath

Copy link
Copy Markdown
Contributor

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

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Oct 3, 2025
@algorithms-keeper algorithms-keeper Bot added the require descriptive names This PR needs descriptive function and/or variable names label Sep 13, 2026

@algorithms-keeper algorithms-keeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: n

"""


def rotate_left32(x: int, k: int) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: x

Please provide descriptive name for the parameter: k

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 13, 2026
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Sep 13, 2026
@cclauss
cclauss merged commit b447c78 into TheAlgorithms:master Sep 13, 2026
6 checks passed
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

require descriptive names This PR needs descriptive function and/or variable names

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants