Store very big numbers in an integer in C

为君一笑 提交于 2021-01-24 11:49:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!