BigInt 类在 C++ 中的基本实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10576314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:14:20  来源:igfitidea点击:

A good and basic implementation of BigInt class in C++

c++bigintegerbigint

提问by Bebeoix

I'm looking for a good and basic BigInt class in C++, I find a lot of implementation but most of the time, it's complex implementation for crypto library...

我在 C++ 中寻找一个好的和基本的 BigInt 类,我找到了很多实现,但大多数时候,它是加密库的复杂实现......

By basic, I mean BigInt can deal with BigInt, long long and strings with operator overloading. If I had time, I had done myself but I do not have time to create an entire BigInt class.

基本上,我的意思是 BigInt 可以处理 BigInt、long long 和带有运算符重载的字符串。如果我有时间,我已经完成了自己但我没有时间创建整个 BigInt 类。

采纳答案by Neil Forrester

Here's one. I haven't used it, but it doesn't look too complex, and it was the first result when I googled "bigint c++".

这是一个。我没用过,但看起来不是很复杂,这是我在google上搜索“bigint c++”的第一个结果。

回答by user2001885

The simplest library I know of is InfInt. It consists of just one header file. Its usage is fairly simple. Here is a sample code:

我所知道的最简单的库是InfInt。它只包含一个头文件。它的用法相当简单。这是一个示例代码:

InfInt myint1 = "15432154865413186646848435184100510168404641560358";
InfInt myint2 = 156341300544608LL;

myint1 *= --myint2 - 3;
std::cout << myint1 << std::endl;

回答by Alex

http://sourceforge.net/projects/cpp-bigint/

http://sourceforge.net/projects/cpp-bigint/

C++ class BigInt that enables the user to work with arbitrary precision integers.

使用户能够使用任意精度整数的 C++ 类 BigInt。