int main()
{
unsigned long long key = 21739827982173982173921739217392173217397213271832193721973291732917321732132173971317382173213782163872163872163872163872163826176728328621321487219372198371298775647326409817402198732198432974329479832749173821732198732173217392173721372193728193782193792173921732171;
}
Compiler says the number I want to assign is too large for the type selected. How can I store this and then perform operations?
C does not have any built-in support for this. You need a "bignum" library (also known as an "arbitrary precision arithmetic" or "multiple precision arithmetic" library). GNU MP is well-documented and popular.
EDIT: I just noticed that your variable is named "key", and the number appears to be roughly 900 bits long. Are you trying to implement RSA? If so you really should use a well-tested cryptographic library; there are dozens of subtle errors you can make in an RSA implementation which will damage your security. Options there include gcrypt, NSS, and OpenSSL. If you can be license-compatible with libgcrypt, I strongly recommend using that, just because its API and documentation are so much better than those of the other two.
You can get a arbitrary-precision integer library from here.
http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic#Arbitrary-precision_software
You can use the arbitrary precision library to deal with big numbers.
OR
You can use double - it has a range of about 300 digits, but only 53 bits of precision, because it's stored as two parts, an exponent and a mantissa. 53 bits gives you a number in the range of 15-18 digits precise
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With