How to handle numbers bigger than machine representative number?
java
Solution
Use java.math.BigInteger.
BigInteger a = new BigInteger("123456789012345678901234567890");
BigInteger b = new BigInteger("314159265");
BigInteger c = a.add(b);
System.out.println(c);
Note (1) `BigInteger`s are immutable and (2) you have to use the methods `add`, `subtract`, etc. rather than `+`, `-`, etc.
Also, `BigInteger` (and its floating-point analog, `BigDecimal`) is much lower slower than primitive types. `BigInteger` is fine for most cases, but avoid it if possible in performance sensitive code.
Problem
Assuming now I'm assigning ID number to my database, the database is huge(items more than machine representative number). I'm using Java, I know the biggest data type in Java is long int(64 bit). How could I deal with numbers bigger than that? One of my solutions is always converting numbers to strings, which will cause the overhead and I still don't figure out how to accumulate the number(bigger than MAX_VALUE) that is meant to converted to strings.