12.1 Big Integers BigInteger objects are useful when we have values that are larger than what type long can handle. Like the values of the primitive integer types, a BigInteger value is encoded in the two's-complement format (see Chapter 2). The class includes methods to perform the basic arithmetic operations on BigInteger objects. The result of such an operation is always a new BigInteger object, since the objects are immutable. The arithmetic methods include abs() , add() , divide() , divide AndRemainder() , max() , min() , mod() , multiply() , negate() , pow() , remainder() , and subtract() . Method signum () returns -1, 0, or +1, depending on whether the value is negative, zero, or positive, respectively. There are also methods that perform some bitwise operations, such as and() , andNot() , bitLength() , clearBit() , flipBit() , not() , or() , setBit() , shiftLeft() , shiftRight() , testBit() , and xor() . Method valueOf() is a "factory method"?ait creates a new BigInteger object from a long value. Method compareTo() compares a BigInteger value to another and returns -1, 0, or +1, depending on whether the value is less than, equal to, or greater than the other, respectively. |
Top |