Fix bit shift calculation for different numeric types (issue #11)#37
Open
Fix bit shift calculation for different numeric types (issue #11)#37
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #11
…ic types - Add tests for uint, ushort, and byte types to verify the existing fix works correctly - The fix already uses NumericType<TLinkAddress>.BitsSize - 1 instead of hardcoded 63 - This resolves issue #11: bit shift now adapts to different numeric type sizes - Tests demonstrate the converter works with 32-bit, 16-bit, and 8-bit types 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
BigIntegerToRawNumberSequenceConverterNumericType<TLinkAddress>.BitsSize - 1instead of hardcoded63uint,ushort, andbytetypes to verify the fix works correctlyProblem Analysis
The original issue was that the bit shift used a hardcoded value
>>= 63(from64 - 1), which only worked correctly for 64-bit types likeulong. This would cause incorrect behavior when using smaller numeric types like:uint(32 bits) - should shift by 31ushort(16 bits) - should shift by 15byte(8 bits) - should shift by 7Solution
The fix was already implemented in the current codebase at
BigIntegerToRawNumberSequenceConverter.cs:96:This dynamically calculates the correct bit shift amount based on the actual size of the generic type parameter.
Test Coverage
Added new test methods to verify the converter works correctly with different numeric types:
UintBitShiftTest()- Tests with 32-bit uintUshortBitShiftTest()- Tests with 16-bit ushortByteBitShiftTest()- Tests with 8-bit byteThese tests ensure the bit masking and shifting logic works correctly for all supported numeric types.
🤖 Generated with Claude Code
Resolves #11