问题
I need to store a very large number as an integer in a C program, unsigned long int
is still too small, I need a very large data type that will still work with the modulo operator (%).
回答1:
There are several libraries that can do this
- GMP
- OpenSSL's BN
If you need it for cryptographic purposes (e.g. RSA as hinted by your need of modulo arithmetic), OpenSSL BN is ideally suited
回答2:
I just want to throw in another library to solve this problem, which I just finished:
- kmbint
It is more lightweight than the previous mentioned libraries. Please be sure that it still solves your needs, as there are some limitations.
As an example you might do modulo operations like this:
char i[20] = "5005";
kmbint_mod(i, "10");
// i is now "5"
来源:https://stackoverflow.com/questions/19212661/store-very-big-numbers-in-an-integer-in-c