## 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

 `42434445464748495051` ```    signature=java.security.Signature.getInstance("SHA1withRSA");     keyFactory=KeyFactory.getInstance("RSA");   }       public void setPubKey(byte[] e, byte[] n) throws Exception{     RSAPublicKeySpec rsaPubKeySpec =   new RSAPublicKeySpec(new BigInteger(n),            new BigInteger(e));     PublicKey pubKey=keyFactory.generatePublic(rsaPubKeySpec);     signature.initVerify(pubKey);   } ```
View Full Code Here

 `49505152535455565758` ```    PublicKey pubKey=keyFactory.generatePublic(rsaPubKeySpec);     signature.initVerify(pubKey);   }   public void setPrvKey(byte[] d, byte[] n) throws Exception{     RSAPrivateKeySpec rsaPrivKeySpec =   new RSAPrivateKeySpec(new BigInteger(n),             new BigInteger(d));     PrivateKey prvKey = keyFactory.generatePrivate(rsaPrivKeySpec);     signature.initSign(prvKey);   } ```
View Full Code Here

 `176177178179180181182183184185186` ```      SimpleMetaType st = (SimpleMetaType)type;             if (SimpleMetaType.BIGDECIMAL.equals(st)) {         return new SimpleValueSupport(st, new BigDecimal(value));       } else if (SimpleMetaType.BIGINTEGER.equals(st)) {         return new SimpleValueSupport(st, new BigInteger(value));       } else if (SimpleMetaType.BOOLEAN.equals(st)) {         return new SimpleValueSupport(st, Boolean.valueOf(value));       } else if (SimpleMetaType.BOOLEAN_PRIMITIVE.equals(st)) {         return new SimpleValueSupport(st, Boolean.valueOf(value).booleanValue());       } else if (SimpleMetaType.BYTE.equals(st)) { ```
View Full Code Here

 `282283284285286287288289290291` ```        }     }         private static class BigIntegerColumnSerializer extends ColumnSerializer {         protected void writeObject(ObjectOutput out, Object obj) throws IOException {             BigInteger val = (BigInteger)obj;             byte[] bytes = val.toByteArray();             out.writeInt(bytes.length);             out.write(bytes);         } ```
View Full Code Here

 `291292293294295296297` ```        }         protected Object readObject(ObjectInput in) throws IOException {             int length = in.readInt();             byte[] bytes = new byte[length];             in.readFully(bytes);             return new BigInteger(bytes);         } ```
View Full Code Here

 `299300301302303304305306307308` ```        private static class BigDecimalColumnSerializer extends ColumnSerializer {         protected void writeObject(ObjectOutput out, Object obj) throws IOException {             BigDecimal val = (BigDecimal)obj;             out.writeInt(val.scale());             BigInteger unscaled = val.unscaledValue();             byte[] bytes = unscaled.toByteArray();             out.writeInt(bytes.length);             out.write(bytes);         } ```
View Full Code Here

 `309310311312313314315` ```        protected Object readObject(ObjectInput in) throws IOException {             int scale = in.readInt();             int length = in.readInt();             byte[] bytes = new byte[length];             in.readFully(bytes);             return new BigDecimal(new BigInteger(bytes), scale);         } ```
View Full Code Here

 `39404142434445464748` ```   * @throws TransformationException if value is an incorrect input type or    * the transformation fails    */   public Object transformDirect(Object value) throws TransformationException {     try {       return new BigInteger(((String)value).trim());     } catch(NumberFormatException e) {       throw new TransformationException("ERR.003.029.0015", CorePlugin.Util.getString("ERR.003.029.0015", value)); //\$NON-NLS-1\$ //\$NON-NLS-2\$     }   } ```
View Full Code Here

 `321322323324325326327` ```    }     // Source = BIGINTEGER         public void testBigIntegerToString() throws Exception {         helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$     } ```
View Full Code Here

 `325326327328329330331` ```    public void testBigIntegerToString() throws Exception {         helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "string", "char(1)"); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$     }     public void testBigIntegerToBoolean() throws Exception {         helpTest(LANG_FACTORY.createLiteral(new BigInteger("1"), BigInteger.class), "boolean", "CASE WHEN 1 = 0 THEN 0 WHEN 1 IS NOT NULL THEN 1 END"); //\$NON-NLS-1\$ //\$NON-NLS-2\$ //\$NON-NLS-3\$     } ```
View Full Code Here