Skip to content

Fix bit shift calculation for different numeric types (issue #11)#37

Open
konard wants to merge 3 commits intomainfrom
issue-11-9a7f9e2b
Open

Fix bit shift calculation for different numeric types (issue #11)#37
konard wants to merge 3 commits intomainfrom
issue-11-9a7f9e2b

Conversation

@konard
Copy link
Member

@konard konard commented Sep 12, 2025

Summary

  • Verified the existing fix for bit shift calculation in BigIntegerToRawNumberSequenceConverter
  • The code now correctly uses NumericType<TLinkAddress>.BitsSize - 1 instead of hardcoded 63
  • Added comprehensive tests for uint, ushort, and byte types to verify the fix works correctly

Problem Analysis

The original issue was that the bit shift used a hardcoded value >>= 63 (from 64 - 1), which only worked correctly for 64-bit types like ulong. This would cause incorrect behavior when using smaller numeric types like:

  • uint (32 bits) - should shift by 31
  • ushort (16 bits) - should shift by 15
  • byte (8 bits) - should shift by 7

Solution

The fix was already implemented in the current codebase at BigIntegerToRawNumberSequenceConverter.cs:96:

currentBigInt >>= (NumericType<TLinkAddress>.BitsSize - 1);

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 uint
  • UshortBitShiftTest() - Tests with 16-bit ushort
  • ByteBitShiftTest() - Tests with 8-bit byte

These tests ensure the bit masking and shifting logic works correctly for all supported numeric types.

🤖 Generated with Claude Code


Resolves #11

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #11
@konard konard self-assigned this Sep 12, 2025
…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>
@konard konard changed the title [WIP] The number of bits should be (numbers size in bits - 1), but not exactly (64 - 1) bit. Fix bit shift calculation for different numeric types (issue #11) Sep 12, 2025
@konard konard marked this pull request as ready for review September 12, 2025 22:22
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.

The number of bits should be (numbers size in bits - 1), but not exactly (64 - 1) bit.

1 participant