Skip to content

Conversation

@Yajunesh
Copy link
Contributor

Implements circular bit rotation utility as requested in #6967

Features:

  • rotateLeft(int value, int shift) - circular left rotation
  • rotateRight(int value, int shift) - circular right rotation
  • 32-bit semantics with shift normalization modulo 32
  • Throws IllegalArgumentException for negative shifts
  • O(1) time complexity with bitwise operations only
  • No external dependencies

Testing:

  • Comprehensive JUnit tests covering typical, boundary, and edge cases
  • Tests for basic rotations, carry operations, shift normalization
  • Complementary operation tests (left/right rotations cancel each other)
  • Exception handling tests

Documentation:

  • Full JavaDoc with examples
  • Wikipedia reference for bit rotation
  • Clear method documentation

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase. (BitRotate.java, BitRotateTest.java)
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations. (Added Wikipedia link)
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Closes #6967

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.34%. Comparing base (d717ca4) to head (45a94ce).

Files with missing lines Patch % Lines
...a/com/thealgorithms/bitmanipulation/BitRotate.java 85.71% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7011      +/-   ##
============================================
+ Coverage     78.33%   78.34%   +0.01%     
- Complexity     6638     6645       +7     
============================================
  Files           748      749       +1     
  Lines         22100    22114      +14     
  Branches       4340     4342       +2     
============================================
+ Hits          17311    17325      +14     
- Misses         4091     4092       +1     
+ Partials        698      697       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@alxkm alxkm left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for the contribution.

@alxkm alxkm merged commit 82ff14c into TheAlgorithms:master Nov 3, 2025
6 checks passed
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 this pull request may close these issues.

[FEATURE REQUEST] Rotate Bits [Left \ Right]

3 participants