Class BigInteger

  • All Implemented Interfaces:
    Comparable

    public class BigInteger
    extends java.lang.Object
    implements Comparable
    Written using on-line Java Platform 1.2 API Specification, as well as "The Java class libraries", 2nd edition (Addison-Wesley, 1998) and "Applied Cryptography, Second Edition" by Bruce Schneier (Wiley, 1996). Based primarily on IntNum.java BitOps.java by Per Bothner (per@bothner.com) (found in Kawa 1.6.62).
    • Field Detail

      • ZERO

        public static final BigInteger ZERO
        The constant zero as a BigInteger.
      • ONE

        public static final BigInteger ONE
        The constant one as a BigInteger.
      • TEN

        public static final BigInteger TEN
        The constant ten as a BigInteger.
    • Method Detail

      • probablePrime

        public static BigInteger probablePrime​(int bitLength,
                                               Random rnd)
        Return a BigInteger that is bitLength bits long with a probability < 2^-100 of being composite.
        Parameters:
        bitLength - length in bits of resulting number
        rnd - random number generator to use
        Throws:
        java.lang.ArithmeticException - if bitLength < 2
      • valueOf

        public static BigInteger valueOf​(long val)
        Return a (possibly-shared) BigInteger with a given long value.
      • signum

        public int signum()
      • compareTo

        public int compareTo​(BigInteger val)
      • pow

        public BigInteger pow​(int exponent)
        Calculate the integral power of a BigInteger.
        Parameters:
        exponent - the exponent (must be non-negative)
      • isProbablePrime

        public boolean isProbablePrime​(int certainty)

        Returns true if this BigInteger is probably prime, false if it's definitely composite. If certainty is <= 0, true is returned.

        Parameters:
        certainty - a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 - 1/2certainty). The execution time of this method is proportional to the value of this parameter.
        Returns:
        true if this BigInteger is probably prime, false if it's definitely composite.
      • shiftLeft

        public BigInteger shiftLeft​(int n)
      • shiftRight

        public BigInteger shiftRight​(int n)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(int radix)
      • toStringBuffer

        public void toStringBuffer​(int radix,
                                   java.lang.StringBuffer sb)
      • intValue

        public int intValue()
      • longValue

        public long longValue()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • doubleValue

        public double doubleValue()
      • bitLength

        public int bitLength()
        Calculates ceiling(log2(this < 0 ? -this : this+1)) See Common Lisp: the Language, 2nd ed, p. 361.
      • toByteArray

        public byte[] toByteArray()
      • and

        public BigInteger and​(BigInteger y)
        Return the logical (bit-wise) "and" of two BigIntegers.
      • or

        public BigInteger or​(BigInteger y)
        Return the logical (bit-wise) "(inclusive) or" of two BigIntegers.
      • xor

        public BigInteger xor​(BigInteger y)
        Return the logical (bit-wise) "exclusive or" of two BigIntegers.
      • not

        public BigInteger not()
        Return the logical (bit-wise) negation of a BigInteger.
      • clearBit

        public BigInteger clearBit​(int n)
      • testBit

        public boolean testBit​(int n)
      • getLowestSetBit

        public int getLowestSetBit()
      • bitCount

        public int bitCount()
        Count one bits in a BigInteger. If argument is negative, count zero bits instead.
      • compareTo

        public int compareTo​(java.lang.Object other)
                      throws java.lang.ClassCastException
        Description copied from interface: Comparable
        Must return > 0 if this object is greater than the other one, < 0 if its smaller, and 0 if they are equal.
        Specified by:
        compareTo in interface Comparable
        Throws:
        java.lang.ClassCastException