feat: add binary shift operations#988
Merged
siriak merged 1 commit intoTheAlgorithms:masterfrom Jan 7, 2026
Merged
Conversation
Contributor
Author
|
@siriak, this is ready to be merged. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #988 +/- ##
==========================================
+ Coverage 95.80% 95.86% +0.05%
==========================================
Files 357 358 +1
Lines 23965 24141 +176
==========================================
+ Hits 22960 23142 +182
+ Misses 1005 999 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
siriak
approved these changes
Jan 7, 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.
Description
This PR adds implementations of four types of binary shift operations to the
bit_manipulationmodule, with binary string output for visualization and educational purposes.Implementation Details
The implementation provides four main functions:
logical_left_shift(number: i32, shift_amount: i32) -> Result<String, String>logical_right_shift(number: i32, shift_amount: i32) -> Result<String, String>arithmetic_left_shift(number: i32, shift_amount: i32) -> Result<String, String>arithmetic_right_shift(number: i32, shift_amount: i32) -> Result<String, String>Algorithm Details
Logical Left Shift:
Logical Right Shift:
Arithmetic Left Shift:
Arithmetic Right Shift:
Key Features
Resultfor error handlingShift Types Explained
Logical Left Shift (<<)
Arithmetic Left Shift (<<)
Logical Right Shift (>>> in some languages)
Arithmetic Right Shift (>>)
Two's Complement Implementation
For negative numbers in arithmetic right shift, the implementation follows Python's approach:
abs(number) - (1 << binary_length)This ensures correct representation of negative numbers in binary form.
Changes Made
src/bit_manipulation/binary_shifts.rswith complete implementationsrc/bit_manipulation/mod.rsto include and export the moduleType of Change
Test Coverage
✅ 35+ Unit Tests Including:
Checklist
cargo fmtcargo clippymod.rsAdditional Context
Resulttype for error handling instead of exceptionsReferences