Skip to content

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

Adds a function to reverse the bits of a 32-bit unsigned integer.

Changes

  • Added reverse_bits.rs to src/bit_manipulation/
  • Updated src/bit_manipulation/mod.rs to include the new module
  • Implemented bit reversal using bitwise operations
  • Added comprehensive tests covering edge cases
  • Added documentation with examples

Algorithm

The function iterates through all 32 bits, shifting the result left and extracting each bit from the input using bitwise AND, then OR-ing it into the result.

Time Complexity: O(1) - Always processes exactly 32 bits
Space Complexity: O(1) - Uses constant extra space

Testing

All tests pass:

  • Basic reversal cases
  • Edge cases (0, 1, u32::MAX)
  • Alternating bit patterns
  • Symmetry property (reversing twice returns original)

@AliAlimohammadi AliAlimohammadi changed the title Add reverse_bits algorithm to bit_manipulation module Add Reverse Bits algorithm to Bit Manipulation module Dec 9, 2025
@AliAlimohammadi
Copy link
Contributor Author

@siriak, This is ready to be merged.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.58%. Comparing base (e753993) to head (19148a6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #963      +/-   ##
==========================================
+ Coverage   95.57%   95.58%   +0.01%     
==========================================
  Files         337      338       +1     
  Lines       22015    22052      +37     
==========================================
+ Hits        21040    21078      +38     
+ Misses        975      974       -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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a bit reversal algorithm to the bit manipulation module, implementing a function that reverses the bits of a 32-bit unsigned integer using bitwise operations. The implementation follows the repository's documentation standards with comprehensive module-level and function-level documentation.

  • Adds reverse_bits function with O(1) time and space complexity
  • Includes comprehensive test coverage for edge cases and typical inputs
  • Properly integrates the new module into the existing codebase structure

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/bit_manipulation/reverse_bits.rs New implementation of bit reversal algorithm with documentation and tests
src/bit_manipulation/mod.rs Module declaration and public export of reverse_bits function
DIRECTORY.md Added reverse_bits entry to documentation index (plus formatting improvements to other entries)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@siriak siriak 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, thanks!

@siriak siriak merged commit 6bed9d5 into TheAlgorithms:master Dec 9, 2025
13 checks passed
@AliAlimohammadi AliAlimohammadi deleted the add-reverse-bits branch December 9, 2025 13:57
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.

3 participants