How can I represent a very large integer in .NET?

.NET 4 has a BigInteger class Represents an arbitrarily large signed integer. The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. This type differs from the other integral types in the .NET Framework, which have a range indicated by their MinValue … Read more

How to add 2 arbitrarily sized integers in C++?

Here’s an example showing how to use the OpenSSL bignum implementation for arbitrary-precision arithmetic. My example does 264 + 265. I’m using Linux. #include <cstdio> #include <openssl/crypto.h> #include <openssl/bn.h> int main(int argc, char *argv[]) { static const char num1[] = “18446744073709551616”; static const char num2[] = “36893488147419103232”; BIGNUM *bn1 = NULL; BIGNUM *bn2 = NULL; … Read more

How to deal with big numbers in javascript [duplicate]

While looking for an big integer library for an ElGamal crypto implementation I tested several libraries with the following results: I recommend this one: Tom Wu’s jsbn.js (http://www-cs-students.stanford.edu/~tjw/jsbn/) Comprehensive set of functions and fast Leemon Baird’s big integer library (http://www.leemon.com/crypto/BigInt.js) Comprehensive set of functions and pretty fast BUT: Negative number representation is buggy! bignumber.js (https://github.com/MikeMcl/bignumber.js) … Read more

Working with large numbers in PHP

For some reason, there are two standard libraries in PHP handling the arbitrary length/precision numbers: BC Math and GMP. I personally prefer GMP, as it’s fresher and has richer API. Based on GMP I’ve implemented Decimal2 class for storing and processing currency amounts (like USD 100.25). A lot of mod calculations there w/o any problems. … Read more

How to implement big int in C++

A fun challenge. 🙂 I assume that you want integers of arbitrary length. I suggest the following approach: Consider the binary nature of the datatype “int”. Think about using simple binary operations to emulate what the circuits in your CPU do when they add things. In case you are interested more in-depth, consider reading this … Read more