Code example for BigInteger

Methods: bitLength, intValue

0
     * Create a prime number of 2 bits length. 
     */ 
    public void testConstructorPrime2() { 
        int bitLen = 2;
        Random rnd = new Random();
        BigInteger aNumber = new BigInteger(bitLen, 80, rnd);
        assertTrue("incorrect bitLength", aNumber.bitLength() == bitLen);
        int num = aNumber.intValue();
        assertTrue("incorrect value", num == 2 || num == 3);
    } 
}