Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A good and basic implementation of BigInt class in C++ [closed]

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...

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.

like image 285
Bebeoix Avatar asked May 14 '12 00:05

Bebeoix


People also ask

What is BigInt in C?

The BIGINT data type is a machine-independent method for representing numbers in the range of -2 63-1 to 2 63-1. ESQL/C provides routines that facilitate the conversion from the BIGINT data type to other data types in the C language. The BIGINT data type is internally represented with the ifx_int8_t structure.

How do you use big integer in CPP?

We can use big integer datatype. We can use different datatypes like int128_t, int256_t, int1024_t etc. By using this we can get precision up to 1024 easily. At first we are multiplying two huge number using boost library.

What is BigInt library?

BigInteger is a . NET 2.0 and Mono library for handling very large integers, up to 10240 binary digits or approximately (safe to use) 3000 decimal digits.


3 Answers

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 myint1 = "15432154865413186646848435184100510168404641560358";
InfInt myint2 = 156341300544608LL;

myint1 *= --myint2 - 3;
std::cout << myint1 << std::endl;
like image 90
user2001885 Avatar answered Oct 20 '22 23:10

user2001885


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

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

like image 31
Alex Avatar answered Oct 21 '22 00:10

Alex


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++".

like image 36
Neil Forrester Avatar answered Oct 20 '22 23:10

Neil Forrester