Java 8 BigInteger - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BigInteger class.

This code example shows how to use the following methods:intValue, toByteArray
public class RoundTripTest 
{ 
    @Test 
    public void testInteger() 
    { 
        BigInteger bi = new BigInteger("1");
        assert bi.intValue() == 1;
        assert IntegerType.instance.getString(IntegerType.instance.fromString("1")).equals("1"); 
        assert IntegerType.instance.fromString(IntegerType.instance.getString(ByteBuffer.wrap(bi.toByteArray())))
                .equals(ByteBuffer.wrap(bi.toByteArray()));
        assert IntegerType.instance.compose(ByteBuffer.wrap(bi.toByteArray())).equals(bi);
        assert IntegerSerializer.instance.toString(bi).equals("1");
    } 
 
    @Test 
    public void testLong() 
    { 
        byte[] v = new byte[]{0,0,0,0,0,0,0,1};
        assert LongType.instance.getString(LongType.instance.fromString("1")).equals("1"); 
        assert LongType.instance.fromString(LongType.instance.getString(ByteBuffer.wrap(v)))
10
CodeRank
This code example shows how to use the following methods:add, subtract
    } 
 
    private static void invalidateIntRange(ModelTypeValidator testee) {
        assertInvalid(testee, new ModelNode().set(BigDecimal.valueOf(Integer.MAX_VALUE).add(BigDecimal.ONE)));
        assertInvalid(testee, new ModelNode().set(BigDecimal.valueOf(Integer.MIN_VALUE).subtract(BigDecimal.ONE)));
        assertInvalid(testee, new ModelNode().set(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.ONE)));
        assertInvalid(testee, new ModelNode().set(BigInteger.valueOf(Integer.MIN_VALUE).subtract(BigInteger.ONE)));
        assertInvalid(testee, new ModelNode().set(Integer.MAX_VALUE + 1L));
        assertInvalid(testee, new ModelNode().set(Integer.MIN_VALUE - 1L));
        assertInvalid(testee, new ModelNode().set(Integer.MAX_VALUE + 1d));
        assertInvalid(testee, new ModelNode().set(Integer.MIN_VALUE - 1d));
    } 
 
    private static void invalidateLongRange(ModelTypeValidator testee) {
        assertInvalid(testee, new ModelNode().set(BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.ONE)));
        assertInvalid(testee, new ModelNode().set(BigDecimal.valueOf(Long.MIN_VALUE).subtract(BigDecimal.ONE)));
        assertInvalid(testee, new ModelNode().set(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)));
        assertInvalid(testee, new ModelNode().set(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE)));
        assertInvalid(testee, new ModelNode().set(Long.MAX_VALUE * 10d));
        assertInvalid(testee, new ModelNode().set(Long.MIN_VALUE * 10d));
8
CodeRank
This code example shows how to use the following methods:
 
        BigInteger integerType;
 
        try 
        { 
            integerType = new BigInteger(source);
        } 
        catch (Exception e)
        { 
            throw new MarshalException(String.format("unable to make int from '%s'", source), e);
        } 
 
        return decompose(integerType);
    } 
 
    public CQL3Type asCQL3Type() 
    { 
        return CQL3Type.Native.VARINT; 
    } 
 
8
CodeRank
This code example shows how to use the following methods:bitLength, mod
        ECPublicKeyParameters   Q2U,
        ECPublicKeyParameters   Q1V,
        ECPublicKeyParameters   Q2V)
    { 
        BigInteger n = parameters.getN();
        int e = (n.bitLength() + 1) / 2;
        BigInteger powE = ECConstants.ONE.shiftLeft(e);
 
        // The Q2U public key is optional 
        ECPoint q;
        if (Q2U == null)
        { 
            q = parameters.getG().multiply(d2U.getD());
        } 
        else 
        { 
            q = Q2U.getQ();
        } 
 
        BigInteger x = q.getX().toBigInteger();

8
CodeRank
This code example shows how to use the following methods:compareTo, modInverse
        BigInteger      k;
        int                  qBitLength = params.getQ().bitLength();
 
        do  
        { 
            k = new BigInteger(qBitLength, random);
        } 
        while (k.compareTo(params.getQ()) >= 0);
 
        BigInteger  r = params.getG().modPow(k, params.getP()).mod(params.getQ());
 
        k = k.modInverse(params.getQ()).multiply(
                    m.add(((DSAPrivateKeyParameters)key).getX().multiply(r)));
 
        BigInteger  s = k.mod(params.getQ());
 
        BigInteger[]  res = new BigInteger[2];
 
        res[0] = r;
        res[1] = s;
8
CodeRank
This code example shows how to use the following methods:toString
        UUID uuid = UUID.randomUUID();
        String sud = uuid.toString();
        System.out.println("uuid="+uuid);
        sud = sud.replaceAll("-", "");
         
        BigInteger integer = new BigInteger(sud,16);
 
        System.out.println("bi ="+integer.toString() );
        return integer;
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:
	private static final int RADIX = 10 + 26; // 10 digits + 26 letters
 
	@Override 
	public String generate(String imageUri) {
		byte[] md5 = getMD5(imageUri.getBytes());
		BigInteger bi = new BigInteger(md5).abs();
		return bi.toString(RADIX);
	} 
 
	private byte[] getMD5(byte[] data) {
		byte[] hash = null;
		try { 
			MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
			digest.update(data);
			hash = digest.digest();
		} catch (NoSuchAlgorithmException e) {
			L.e(e);
		} 
		return hash;
	} 
7
CodeRank
This code example shows how to use the following methods:equals
        KeyFactory keyFact = KeyFactory.getInstance("DSA", "BC");
 
        PrivateKey privKey = keyFact.generatePrivate(privKeySpec);
 
        doTestHMACDetDSASample("SHA1withDETDSA", privKey, new BigInteger("2E1A0C2562B2912CAAF89186FB0F42001585DA55", 16), new BigInteger("29EFB6B0AFF2D7A68EB70CA313022253B9A88DF5", 16));
        doTestHMACDetDSASample("SHA224withDETDSA", privKey, new BigInteger("4BC3B686AEA70145856814A6F1BB53346F02101E", 16), new BigInteger("410697B92295D994D21EDD2F4ADA85566F6F94C1", 16));
        doTestHMACDetDSASample("SHA256withDETDSA", privKey, new BigInteger("81F2F5850BE5BC123C43F71A3033E9384611C545", 16), new BigInteger("4CDD914B65EB6C66A8AAAD27299BEE6B035F5E89", 16));
        doTestHMACDetDSASample("SHA384withDETDSA", privKey, new BigInteger("07F2108557EE0E3921BC1774F1CA9B410B4CE65A", 16), new BigInteger("54DF70456C86FAC10FAB47C1949AB83F2C6F7595", 16));
        doTestHMACDetDSASample("SHA512withDETDSA", privKey, new BigInteger("16C3491F9B8C3FBBDD5E7A7B667057F0D8EE8E1B", 16), new BigInteger("02C36A127A7B89EDBB72E4FFBC71DABC7D4FC69C", 16));
    } 
 
    private void doTestHMACDetDSASample(String algName, PrivateKey privKey, BigInteger r, BigInteger s)
        throws Exception 
    { 
        doTestHMACDetECDSA(Signature.getInstance(algName, "BC"), SAMPLE, privKey, r, s);
    } 
 
    // test vectors from appendix in RFC 6979 
    private void testECHMacDeterministic() 
        throws Exception 

7
CodeRank
This code example shows how to use the following methods:compareTo, subtract, toByteArray
    private static final BigInteger ZERO = BigInteger.valueOf(0);
 
    private final HMac hMac;
    private final byte[] K;
    private final byte[] V;
 
    private BigInteger n;
 
    /** 
     * Base constructor. 
     * 
     * @param digest digest to build the HMAC on. 
     */ 
    public HMacDSAKCalculator(Digest digest)
    { 
        this.hMac = new HMac(digest);
        this.V = new byte[hMac.getMacSize()];
        this.K = new byte[hMac.getMacSize()];
    } 
 
7
CodeRank
This code example shows how to use the following methods:bitLength, longValue
        return ret;
    } 
     
    public static long toLong(String values) throws NumberFormatException {
        // Long.parseLong() can't handle HexStrings with MSB set. Sigh.  
        BigInteger bi = new BigInteger(values.replaceAll(":", ""),16);
        if (bi.bitLength() > 64) 
            throw new NumberFormatException("Input string too big to fit in long: " + values);
        return bi.longValue();
    } 
 
} 
7
CodeRank

Related Java 8 BigInteger Questions & Answers:

See Code Examples for Java 8 BigInteger Methods: