My first code. Just pure math and java. The numbers are represented as a bit (boolean) array, they can be very big, but it works quite slowly. Operations: string parsing, parsing of the big/little endian byte array, addition, subtraction, multiplication, division with remainder, bit shift, square root, least common multiple, modulus power and inverse, primality test.
Create source and output directories.
$ mkdir -p src/com/aqoleg out
Download the package: BigInteger.java.
$ wget -O src/com/aqoleg/BigInteger.java biginteger.aqoleg.com/src/com/aqoleg/BigInteger.java
Compile.
$ javac -d out src/com/aqoleg/BigInteger.java
Create jar file.
$ cd out
$ jar cf ../BigInteger.jar ./
$ cd ../
Directories out, src and file BigInteger.jar will remain after all.
Build the jar file as described above, or download BigInteger.jar.
$ wget biginteger.aqoleg.com/BigInteger.jar
Create test and output directories.
$ mkdir -p test/com/aqoleg out
Download the test package: BigIntegerTest.java.
$ wget -O test/com/aqoleg/BigIntegerTest.java biginteger.aqoleg.com/test/com/aqoleg/BigIntegerTest.java
Compile.
$ javac -d out -cp BigInteger.jar test/com/aqoleg/BigIntegerTest.java
Run and read results.
$ java -cp out:BigInteger.jar com.aqoleg.BigIntegerTest
Directories out, test and file BigInteger.jar will remain after all.
Build the jar file as described above, or download BigInteger.jar.
$ wget biginteger.aqoleg.com/BigInteger.jar
Create example.
$ cat > Example.java
Copy-paste this example, then press ctrl + D.
import com.aqoleg.BigInteger;
public class Example {
public static void main(String args[]) {
BigInteger a = BigInteger.parse("0x8236639764796396343434547657387482748");
a = a.add(BigInteger.parse("0x3083758048578475878758390893859385"));
System.out.println(a.isqrt().toHexString(true));
}
}
Compile.
$ javac -cp BigInteger.jar Example.java
Run and read result 0x02DA576DF359FE4B1083.
$ java -cp .:BigInteger.jar Example
Files Example.class, Example.java, BigInteger.jar will remain after all.
Create source and output directories.
$ mkdir -p src/com/aqoleg out
Download the package: BigInteger.java.
$ wget -O src/com/aqoleg/BigInteger.java biginteger.aqoleg.com/src/com/aqoleg/BigInteger.java
Download the example: Example.java.
$ wget -O src/Example.java biginteger.aqoleg.com/src/Example.java
Compile.
$ javac -d out -cp src src/Example.java
Create jar file.
$ cd out
$ jar cfe ../Example.jar Example ./
$ cd ../
Run and read results 0xF234FF3532454A888666873B, 0x23345353424FF3532445EDDD0268, 0x014B3AD3EE1D66368E94733D03168357D088, 0xB8FA53E555152FB27F5328.
$ java -jar Example.jar 0xF234FF353244535397788734 add 0xF734EEEE0007
$ java -jar Example.jar 0x23345353424FF3532445FFFFFF34 sub 0x1222FCCC
$ java -jar Example.jar 0x12434FFFDCDD788734 mul 0x122300000877878AAA
$ java -jar Example.jar 0x197AA243555344BBCDEFFEDCC345 div 0x2342FF
Directories out, src and file Example.jar will remain after all.