## Examples of java.math.BigInteger

• java.math.BigInteger
Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in two's-complement notation (like Java's primitive integer types). BigInteger provides analogues to all of Java's primitive integer operators, and all relevant methods from java.lang.Math. Additionally, BigInteger provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.

Semantics of arithmetic operations exactly mimic those of Java's integer arithmetic operators, as defined in The Java Language Specification. For example, division by zero throws an {@code ArithmeticException}, and division of a negative by a positive yields a negative (or zero) remainder. All of the details in the Spec concerning overflow are ignored, as BigIntegers are made as large as necessary to accommodate the results of an operation.

Semantics of shift operations extend those of Java's shift operators to allow for negative shift distances. A right-shift with a negative shift distance results in a left shift, and vice-versa. The unsigned right shift operator ( {@code >>>}) is omitted, as this operation makes little sense in combination with the "infinite word size" abstraction provided by this class.

Semantics of bitwise logical operations exactly mimic those of Java's bitwise integer operators. The binary operators ( {@code and}, {@code or}, {@code xor}) implicitly perform sign extension on the shorter of the two operands prior to performing the operation.

Comparison operations perform signed integer comparisons, analogous to those performed by Java's relational and equality operators.

Modular arithmetic operations are provided to compute residues, perform exponentiation, and compute multiplicative inverses. These methods always return a non-negative result, between {@code 0} and {@code (modulus - 1)}, inclusive.

Bit operations operate on a single bit of the two's-complement representation of their operand. If necessary, the operand is sign- extended so that it contains the designated bit. None of the single-bit operations can produce a BigInteger with a different sign from the BigInteger being operated on, as they affect only a single bit, and the "infinite word size" abstraction provided by this class ensures that there are infinitely many "virtual sign bits" preceding each BigInteger.

For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigInteger methods. The pseudo-code expression {@code (i + j)} is shorthand for "a BigInteger whose value isthat of the BigInteger {@code i} plus that of the BigInteger {@code j}." The pseudo-code expression {@code (i == j)} is shorthand for" {@code true} if and only if the BigInteger {@code i} represents the samevalue as the BigInteger {@code j}." Other pseudo-code expressions are interpreted similarly.

All methods and constructors in this class throw {@code NullPointerException} when passeda null object reference for any input parameter. @see BigDecimal @author Josh Bloch @author Michael McCloskey @since JDK1.1

 `65596560656165626563656465656566656765686569` ```                String sql = "SELECT BigIntegerValue FROM VQT.Defect15355 WHERE StringKey LIKE '%0' AND StringKey LIKE '0%'";  //\$NON-NLS-1\$                 // Create expected results         List[] expected = new List[] {             Arrays.asList(new Object[] { new BigInteger("0") }), //\$NON-NLS-1\$          };                    // Construct data manager with data         FakeDataManager dataManager = new FakeDataManager();         sampleDataBQT2a(dataManager); ```
View Full Code Here

 `65896590659165926593659465956596659765986599` ```                String sql = "SELECT BigIntegerValue AS a, BigIntegerValue AS b FROM VQT.Defect15355 WHERE StringKey = '0'";  //\$NON-NLS-1\$                 // Create expected results         List[] expected = new List[] {             Arrays.asList(new Object[] { new BigInteger("0"), new BigInteger("0") }), //\$NON-NLS-1\$  //\$NON-NLS-2\$         };                    // Construct data manager with data         FakeDataManager dataManager = new FakeDataManager();         sampleDataBQT2a(dataManager); ```
View Full Code Here

 `66496650665166526653665466556656665766586659` ```                String sql = "SELECT BigIntegerValue FROM VQT.Defect15355b WHERE BigIntegerValue = '0'";  //\$NON-NLS-1\$                 // Create expected results         List[] expected = new List[] {             Arrays.asList(new Object[] { new BigInteger("0") }), //\$NON-NLS-1\$          };                    // Construct data manager with data         FakeDataManager dataManager = new FakeDataManager();         sampleDataBQT2a(dataManager); ```
View Full Code Here

 `7372737373747375737673777378737973807381738273837384` ```        FakeMetadataFacade metadata = FakeMetadataFactory.example1Cached();                 ProcessorPlan plan = helpGetPlan(helpParse(sql), metadata, TestOptimizer.getGenericFinder());                 List[] expected = new List[] {             Arrays.asList(new Object[] { new BigInteger("0") }), //\$NON-NLS-1\$             Arrays.asList(new Object[] { new BigInteger("3") }), //\$NON-NLS-1\$             Arrays.asList(new Object[] { new BigInteger("0") }), //\$NON-NLS-1\$         };         FakeDataManager manager = new FakeDataManager();         sampleData1(manager);         helpProcess(plan, manager, expected); ```
View Full Code Here

 `260261262263264265266267268269270271272273274275276277278279` ```            //     3 or 4 - digestEncryptionAlgorithm             //     4 or 5 - encryptedDigest             signerversion = ((DERInteger)signerInfo.getObjectAt(0)).getValue().intValue();             // Get the signing certificate             ASN1Sequence issuerAndSerialNumber = (ASN1Sequence)signerInfo.getObjectAt(1);             BigInteger serialNumber = ((DERInteger)issuerAndSerialNumber.getObjectAt(1)).getValue();             for (Iterator i = certs.iterator(); i.hasNext();) {                 X509Certificate cert = (X509Certificate)i.next();                 if (serialNumber.equals(cert.getSerialNumber())) {                     signCert = cert;                     break;                 }             }             if (signCert == null) {                 throw new IllegalArgumentException("Can't find signing certificate with serial " + serialNumber.toString(16));             }             digestAlgorithm = ((DERObjectIdentifier)((ASN1Sequence)signerInfo.getObjectAt(2)).getObjectAt(0)).getId();             next = 3;             if (signerInfo.getObjectAt(next) instanceof ASN1TaggedObject) {                 ASN1TaggedObject tagsig = (ASN1TaggedObject)signerInfo.getObjectAt(next); ```
View Full Code Here

 `7475767778798081828384` ```        value = XMLValueTranslator.translateToXMLValue(ts, DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);         assertEquals("-0102-12-30T09:04:05Z", value); //\$NON-NLS-1\$     }         @Test public void testgYearTranslation() throws Exception {         String value = XMLValueTranslator.translateToXMLValue(new BigInteger("5"), DataTypeManager.DefaultDataClasses.BIG_INTEGER, XMLValueTranslator.GYEAR); //\$NON-NLS-1\$         assertEquals("0005", value); //\$NON-NLS-1\$         value = XMLValueTranslator.translateToXMLValue(new BigInteger("-10000"), DataTypeManager.DefaultDataClasses.BIG_INTEGER, XMLValueTranslator.GYEAR); //\$NON-NLS-1\$         assertEquals("-10000", value); //\$NON-NLS-1\$     } ```
View Full Code Here

 `10681069107010711072107310741075107610771078` ```                // This needs to match what's in FakeMetadataFactory.example1 for this stored proc         return new Object[]  {             new Constant("x"), //\$NON-NLS-1\$             new Constant(new BigDecimal("13.0")),//\$NON-NLS-1\$             new Constant(new BigInteger("13")),//\$NON-NLS-1\$             new Constant(Boolean.TRUE),             new Constant(new Byte("1")),//\$NON-NLS-1\$             new Constant(new Character('q')),             new Constant(Date.valueOf("2003-03-20")),//\$NON-NLS-1\$             new Constant(new Double(13.0)), ```
View Full Code Here

 `107108109110111112113114115116117` ```        List[] batch = new List[rows];                 for (int i = 0; i < rows; i++) {             long currentTime = System.currentTimeMillis();             Object[] data = { new BigDecimal("" + i), //\$NON-NLS-1\$                               new BigInteger(Integer.toString(i)),                               (i%2 == 0) ? Boolean.FALSE: Boolean.TRUE,                               new Byte((byte)i),                               new Character((char)i),                               new Date(currentTime),                               new Double(i), ```
View Full Code Here

 `133134135136137138139140141142143` ```                for (int i = 0; i < rows; i++) {             long currentTime = System.currentTimeMillis();             int mod = i%14;             Object[] data = { (mod == 0) ? null : new BigDecimal("" + i), //\$NON-NLS-1\$                               (mod == 1) ? null : new BigInteger(Integer.toString(i)),                               (mod == 2) ? null : ((i%2 == 0) ? Boolean.FALSE: Boolean.TRUE),                               (mod == 3) ? null : new Byte((byte)i),                               (mod == 4) ? null : new Character((char)i),                               (mod == 5) ? null : new Date(currentTime),                               (mod == 6) ? null : new Double(i), ```
View Full Code Here

 `156157158159160161162` ```     * @param value the value      * @param scale the scale      * @return the big decimal object      */     BigDecimal getBigDecimal(int value, int scale) {         return new BigDecimal(new BigInteger(String.valueOf(value)), scale);     } ```
View Full Code Here