Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukellmann
Copy link
Member

DiscordBitSet can only represent positive numbers, so the BigInteger used for getting a decimal representation can be constructed using the sign-magnitude representation instead of the two's-complement binary representation.

This fixes two bugs:

  • DiscordBitSets with an empty data array couldn't be converted to a BigInteger because the constructor taking the two's-complement binary representation throws a NumberFormatException if the given array is empty.
    This bug was reported by @Tmpod: https://discord.com/channels/556525343595298817/1147254164469063773

  • DiscordBitSets with a negative Long at the last position in their data array would be misinterpreted as negative numbers in the conversion to BigIntegers because the two's-complement binary representation was used.
    Example where this bug could be observed:

// printed -9223372036854775808, should be 9223372036854775808
println(DiscordBitSet(1L shl 63).value)

DiscordBitSet can only represent positive numbers, so the BigInteger
used for getting a decimal representation can be constructed using the
sign-magnitude representation instead of the two's-complement binary
representation.

This fixes two bugs:

 * DiscordBitSets with an empty data array couldn't be converted to a
   BigInteger because the constructor taking the two's-complement binary
   representation throws a NumberFormatException if the given array is
   empty.
   This bug was reported by @Tmpod:
   https://discord.com/channels/556525343595298817/1147254164469063773

 * DiscordBitSets with a negative Long at the last position in their
   data array would be misinterpreted as negative numbers in the
   conversion to BigIntegers because the two's-complement binary
   representation was used.
   Example where this bug could be observed:
   // printed -9223372036854775808, should be 9223372036854775808
   println(DiscordBitSet(1L shl 63).value)
@lukellmann lukellmann merged commit 6749400 into main Sep 2, 2023
@lukellmann lukellmann deleted the fix-bitset-value branch September 2, 2023 01:34
@Tmpod
Copy link
Contributor

Tmpod commented Sep 3, 2023

Tested this on my affected project and it's all good now, thank you!

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.

2 participants