-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How could I get/set n-th bit of BigInt
?
#172
Comments
I can't think of a fast way to do it with the public API right now, but we could add methods like ramp's. Can you offer the some example motivation of what you would use this for? |
Thank you for your comment.
I am trying making big prime numbers by a randomized algorithm now. This is needed for a cryptographic algorithm that I am researching on. In this method, one will try making a random integer and check if it is prime or not many times. To reduce useless attempts, Other good big-integer libraries depends on C language, but yours is made of pure Rust. This is also a good point for my purpose. |
For For (Do not copy ramp's implementation, because the licenses are different.) |
I am currently working on this, so a PR should be coming soon! |
@janmarthedal how's the PR going? I also need this feature (the only reason why I use rug now is that function is missing) |
@mkaczanowski I have submitted a PR so I guess it is up to the project maintainers now. |
183: Get/set n-th bit of `BigUint` and `BigInt` r=cuviper a=janmarthedal This PR implements `bit` and `set_bit` for `BigUint` and `BigInt`. The method names have been chosen to match those of Ramp (https://docs.rs/ramp/0.5.9/ramp/int/struct.Int.html#method.bit). For `BigInt` the implementation uses the number's two's complement representation when the number is negative. This matches what libraries like Ramp or languages like Python do. Resolves #172 Co-authored-by: Jan Marthedal Rasmussen <jan@janmr.com> Co-authored-by: Josh Stone <cuviper@gmail.com>
Nice work! Thanks, @cuviper @janmarthedal |
@cuviper @janmarthedal Thank you so much. Today, I confirmed that my program got faster using your |
Would you do me a favor? I need some help.
I'd like to get and set$n$ -th bit of
BigInt
. How could I do it in a fast way?For example, ramp has such methods;
bit
andset_bit
.I know that I can do it by bitwise operation such as
(x >> bit) & BigInt::one() == BigInt::one()
or so on. But I need faster way.I would be grateful if you could give me advice.
The text was updated successfully, but these errors were encountered: