Example usage for java.math BigInteger divide

List of usage examples for java.math BigInteger divide

Introduction

In this page you can find the example usage for java.math BigInteger divide.

Prototype

public BigInteger divide(BigInteger val) 

Source Link

Document

Returns a BigInteger whose value is (this / val) .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigInteger bi1 = new BigInteger("1234567890123456890");
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.divide(bi2);

}

From source file:Main.java

public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("-100");
    BigInteger bi2 = new BigInteger("3");

    // divide bi1 with bi2
    BigInteger bi3 = bi1.divide(bi2);

    System.out.println(bi3);/* w  w w . j  a  v a  2s  . co  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigInteger bi1 = new BigInteger("1234567890123456890");
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.multiply(bi2);//ww  w.jav  a  2 s.c  o  m

    bi1 = bi1.subtract(bi2);

    bi1 = bi1.divide(bi2);

    bi1 = bi1.negate();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create via a string
    BigInteger bi1 = new BigInteger("1234567890123456890");

    // Create via a long
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.add(bi2);//from   w w  w .ja va2s  .co  m
    bi1 = bi1.multiply(bi2);
    bi1 = bi1.subtract(bi2);
    bi1 = bi1.divide(bi2);
    bi1 = bi1.negate();
    int exponent = 2;
    bi1 = bi1.pow(exponent);

}

From source file:strat.mining.stratum.proxy.test.Test.java

public static void main(String[] args) {
    // List<String> merkleBranches = new ArrayList<String>();
    // merkleBranches.add("32bac6b596b722100e6d0d5a451ec78b4252161603e5c140ce61ce29f1451ff9");
    // merkleBranches.add("0808cdd8a165d9151856258b7ce65c476220afc669e56076f5f7b541099de3d4");
    // merkleBranches.add("8ecfcf4d911ae073f90af0d63cafc37daf35947f766310df4a37e67339713ee4");
    // merkleBranches.add("3b33a4f5d3a406c5760415cd2c71442e082dffb261f1f1abcb905180143d7b63");
    // GetworkJobTemplate arf = new GetworkJobTemplate("1850", "00000002",
    // "72417428ad46bd3265c270b1d1c2dee6723136c98e3cff7be0b72b8ed00e012f",
    // "5396f810", "1b0616be", merkleBranches,
    // "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff230362e608062f503253482f0412f8965308",
    // "092f7374726174756d2f000000000100c6362a010000001976a914c8f58075fdf2ba12619f34d15385567e5a1cb99488ac00000000",
    // "0861e04900");
    ////from  w  ww.  jav  a2 s  . com
    // arf.setDifficulty(700, true);
    //
    // long nanoTime = System.nanoTime();
    // for (int i = 0; i < 100000; i++) {
    // GetworkRequestResult data = arf.getData("000001");
    // }
    // nanoTime = System.nanoTime() - nanoTime;
    // System.out.println("Time: " + (nanoTime / 1000000) + " ms");

    // String splittedData =
    // "0000000206586cdb5fd4a83a94a352104ca66e9b558f996d23c54e720000000000000000c54c4a2c242902deca483072c9ed7ba89a0b210ca4351fc6e651c164";
    // byte[] hexSplitted = HexUtils.convert(splittedData);
    // // hexSplitted = ArrayUtils.reverseWords(hexSplitted, 4);
    //
    // byte[] hexHash = HashingUtils.midstateSHA256Python(hexSplitted);
    // String midstateComputed = HexUtils.convert(hexHash);
    // String midstate =
    // "ca9a8af983d2639900381eafe0b724d2ac3dd108f1e216af8cf2eefcc83b7854";

    // String target =
    // "00000000000000000000000000000000000000000000000000f0ff0f00000000";
    // BigInteger targetInteger = new BigInteger(HexUtils.convert(target));
    // boolean result = SHA256HashingUtils
    // .isBlockHeaderSHA256HashBelowTarget(
    // "00000002628786d847d7f2a8fca81a6efecc417927728df111ad8bd200000000000000008940c01a70f63c3d68b32e1df36c737f14851923fa45afb4a04dd36da2e2229153aab2eb1851aba267d0f624000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000",
    // targetInteger);

    // String littleEndianBlockHeaderHex =
    // "01000000ae178934851bfa0e83ccb6a3fc4bfddff3641e104b6c4680c31509074e699be2bd672d8d2199ef37a59678f92443083e3b85edef8b45c71759371f823bab59a97126614f44d5001d45920180";
    // byte[] binaryBlockHeader =
    // HexUtils.convert(littleEndianBlockHeaderHex);
    // byte[] scryptHash = ScryptHashingUtils.scryptHash(binaryBlockHeader);
    //
    // long start = System.currentTimeMillis();
    // for (int i = 0; i < 1000; i++) {
    // scryptHash = ScryptHashingUtils.scryptHash(binaryBlockHeader);
    // }
    // System.out.println(System.currentTimeMillis() - start);

    String blockHeaderHex = "00000001c611fe9368eff46ba671b9510a0a4e27d845d5071b782695bf42326b5759dbafba46e9ccf3bd7c4f1efdb822237220527a83abaf263e6200ce46cc940008ebe6540c547c1b6ab9edfdbeb299";

    byte[] binaryBlockHeader = HexUtils.convert(blockHeaderHex);
    byte[] littleEndianHeaderBinary = ArrayUtils.swapBytes(binaryBlockHeader, 4);

    byte[] scryptHash = ScryptHashingUtils.scryptHash(littleEndianHeaderBinary);

    String rawHash = HexUtils.convert(scryptHash);
    System.out.println(rawHash);

    String bigEndian = HexUtils.convert(ArrayUtils.swapBytes(scryptHash, 4));
    System.out.println(bigEndian);

    String bigEndianReversed = HexUtils
            .convert(ArrayUtils.reverseWords(ArrayUtils.swapBytes(scryptHash, 4), 4));
    System.out.println(bigEndianReversed);

    BigInteger hashInt = new BigInteger(org.apache.commons.lang.ArrayUtils.addAll(new byte[] { (byte) 0 },
            ArrayUtils.reverseWords(ArrayUtils.swapBytes(scryptHash, 4), 4)));

    BigInteger diff1Int = ScryptHashingUtils.DIFFICULTY_1_TARGET.toBigInteger();

    BigInteger diff = diff1Int.divide(hashInt);

}

From source file:Main.java

public static void main(String[] args) {
    BigInteger numberA = new BigInteger("98765432123456789");
    BigInteger numberB = BigInteger.TEN;

    numberA = numberA.add(numberB);//w  ww  . jav  a 2s .  co  m
    System.out.println("numberA = " + numberA);

    numberA = numberA.multiply(numberB);
    System.out.println("numberA = " + numberA);

    numberA = numberA.subtract(numberB);
    System.out.println("numberA = " + numberA);

    numberA = numberA.divide(numberB);
    System.out.println("numberA = " + numberA);

    numberA = numberA.mod(numberB);
    System.out.println("numberA = " + numberA);

    numberA = numberA.pow(2);
    System.out.println("numberA = " + numberA);

    numberA = numberA.negate();
    System.out.println("numberA = " + numberA);
}

From source file:Main.java

public static String bigInteger2str(BigInteger amount) {

    return (amount.divide((BigInteger.valueOf(100l)))).toString();
}

From source file:Main.java

public static String getValueShortString(BigInteger number) {
    BigInteger result = number;
    int pow = 0;//from   ww w.j a  v a 2 s .c  om
    while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) {
        result = result.divide(_1000_);
        pow += 3;
    }
    return result.toString() + "\u00b7(" + "10^" + pow + ")";
}

From source file:Main.java

public static BigInteger sqrt(final BigInteger val) {
    final BigInteger two = BigInteger.valueOf(2);
    BigInteger a = BigInteger.ONE.shiftLeft(val.bitLength() / 2);
    BigInteger b;//from  w  w  w.  j  av  a  2s  .  c  o  m
    do {
        b = val.divide(a);
        a = (a.add(b)).divide(two);
    } while (a.subtract(b).abs().compareTo(two) >= 0);
    return a;
}

From source file:org.apache.hadoop.hbase.manual.utils.HBaseUtils.java

/**
 * Splits the given BigInteger into numberOfSplits parts
 * @param maxValue//from w w w  .  j  a v a 2 s  . c o m
 * @param numberOfSplits
 * @return array of BigInteger which is of size (numberOfSplits-1)
 */
private static BigInteger[] split(BigInteger maxValue, int numberOfSplits) {
    BigInteger[] splits = new BigInteger[numberOfSplits - 1];
    BigInteger sizeOfEachSplit = maxValue.divide(BigInteger.valueOf(numberOfSplits));
    for (int i = 1; i < numberOfSplits; i++) {
        splits[i - 1] = sizeOfEachSplit.multiply(BigInteger.valueOf(i));
    }
    return splits;
}