C++ handling very large integers

Tomek, it sounds like you aren’t linking to the BigInteger code correctly. I think you should resolve this problem rather than looking for a new library. I took a look at the source, and BigInteger::BigInteger(int) is most definitely defined. A brief glance indicates that the others are as well. The link errors you’re getting imply … Read more

JSON transfer of bigint: 12000000000002539 is converted to 12000000000002540?

The value is actually not exceeding the maximum numeric value in JavaScript (which is “only” 1.7308 or so). However, the value is exceeding the range of “integral precision”. It is not that the wrong number is sent: rather, it is that the literal 12000000000002539 can only be represented as precisely as 12000000000002540, and thus there … Read more

BigInteger to Hex/Decimal/Octal/Binary strings?

Convert BigInteger to decimal, hex, binary, octal string: Let’s start with a BigInteger value: BigInteger bigint = BigInteger.Parse(“123456789012345678901234567890”); Base 10 and Base 16 The built-in Base 10 (decimal) and base 16 (hexadecimal) conversions are easy: // Convert to base 10 (decimal): string base10 = bigint.ToString(); // Convert to base 16 (hexadecimal): string base16 = bigint.ToString(“X”); … Read more

How to use BigInteger?

BigInteger is immutable. The javadocs states that add() “[r]eturns a BigInteger whose value is (this + val).” Therefore, you can’t change sum, you need to reassign the result of the add method to sum variable. sum = sum.add(BigInteger.valueOf(i));