Big Integer Class

Big Integer class extends Number and implements Comparable interface. It provides analogues to all of Java's primitive integer operators and all methods from java.lang.Math package.

It consists of many methods or operations for modular arithmetic, GCD and many others which are described below.

abs()It returns a BigInteger whose value is the absolute value of this BigInteger.
add()This method returns a BigInteger by simply computing 'this + val' value.
and()This method returns a BigInteger by computing 'this & val ' value.
andNot()This method returns a BigInteger by computing 'this & ~val ' value.
bitCount()This method returns the number of bits in the two's complement representation of this BigInteger which differs from its sign bit.
bitLength()This method returns the number of bits in the minimum two's complement representation of this sign bit excluding the sign bit.
clearBit()This method returns a BigInteger whose value is equal to this BigInteger whose designated bit is cleared.
compareTo()This method compares this BigInteger with the specified BigInteger.
divide()This method returns a BigInteger by computing 'this /~val ' value.
divideAndRemainder()This method returns a BigInteger by computing 'this & ~val ' value followed by 'this%value'.
doubleValue()This method converts this BigInteger to double.
equals()This method compares this BigInteger with the given Object for equality.
flipBit()This method returns a BigInteger whose value is equal to this BigInteger with the designated bit flipped.
floatValue()This method converts this BigInteger to float.
gcd()This method returns a BigInteger whose value is the greatest common divisor between abs(this)and abs(val).
getLowestSetBit()This method returns the index of the rightmost one bit(lowest-order) in this BigInteger (the number of zero bits to the right of the rightmost one bit).
hashCode()This method returns the hash code for this BigInteger.
intValue()This method converts this BigInteger to an int.
isProbablePrime()This method returns a Boolean value 'true' if and only if this BigInteger is prime else for composite values it return false.
longValue()This method coverts this BigInteger to a long.
max()This method returns the maximum between this BigInteger and val.
min()This method returns the minimum between this BigInteger and val.
mod()This method returns a BigInteger value for this mod m.
modInverse()This method returns a BigInteger whose value is 'this inverse mod m'.
modPow()This method returns a BigInteger whose value is 'thisexponent mod m'.
multiply()This method returns a BigInteger by computing 'this *val ' value.
negate()This method returns a BigInteger whose value is '-this'.
nextProbablePrime()This method returns the next prime integer that is greater than this BigInteger.
not()This method returns a BigInteger whose value is '~this'.
or()This method returns a BigInteger whose value is 'this | val'
pow()This method returns a BigInteger whose value is 'thisexponent'.
probablePrime()This method returns a positive prime BigInteger, with the specified bitLength.
remainder()This method returns a BigInteger whose value is 'this % val'.
setBit()This method returns a BigInteger whose value is equal to this BigInteger with the designated bit set.
shiftLeft()This method returns a BigInteger whose value is 'this << val'.
shiftRight()This method returns a BigInteger whose value is 'this >> val'.
signum()This method returns the signum function of this BigInteger.
subtract()This method returns a BigInteger whose value is 'this - val'.
testbit()This method returns a Boolean value 'true' if the designated bit is set.
toByteArray()This method returns a byte array containing the two's-complement representation of this BigInteger.
toString()This method returns the decimal String representation of this BigInteger.
valueOf()This method returns a BigInteger whose value is equivalent to that of the specified long.
xor()This method returns a BigInteger ny computing 'this ^ val ' value.

Example 1

Test it Now

Output:

Factorial of 4 : 24
IsProbablePrime method will return : true
Prime Number next to 197 : 199
Min value : 24
Maximum value : 197

Example 2

Test it Now

Output:

Signum value for 171 : 1
171-17 : 154
171 / 17 :     Quotient : 10       Remaider : 17
 ShiftLeft value : 272

Next TopicJava BigInteger




Latest Courses