当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.shiftLeft方法代码示例

本文整理汇总了Java中java.math.BigInteger.shiftLeft方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.shiftLeft方法的具体用法?Java BigInteger.shiftLeft怎么用?Java BigInteger.shiftLeft使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.shiftLeft方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: detectCurrentParams

import java.math.BigInteger; //导入方法依赖的package包/类
public TransactionParams detectCurrentParams(BigInteger maxGasPrice, BigInteger maxGasLimit, FunctionCall call, BigInteger value) throws IOException {
    BigInteger nonce = getNonce();
    BigInteger blockGasLimit = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock().getGasLimit();
    
    EthEstimateGas gas = web3j.ethEstimateGas(new Transaction(getFromAddress(), nonce, maxGasPrice, blockGasLimit, call.contractAddress, value, call.data)).send();
    BigInteger actualGasLimit = maxGasLimit;

    if (rpc.isFailFast()) {
        CallUtil.checkError(gas, call.toString());
    } 
    if (gas.getError() == null) {
        BigInteger amountUsed = gas.getAmountUsed();
        if (amountUsed.compareTo(maxGasLimit) >= 0) {
            throw new IllegalStateException(String.format("Estimate out of gas, used: %s, limit: %s, block limit: %s, from: %s, %s", amountUsed, maxGasLimit, blockGasLimit, getFromAddress(), call));
        }
        BigInteger estimateAmount = amountUsed.shiftLeft(1);
        if (estimateAmount.compareTo(maxGasLimit) < 0) {
            actualGasLimit = estimateAmount;
        }
    } else {
        log.warn("Transaction will fail from {}: {}", getFromAddress(), call);
    }
    EthGasPrice gasPrice = web3j.ethGasPrice().send();
    CallUtil.checkError(gasPrice);
    BigInteger actualGasPrice = gasPrice.getGasPrice();
    if (actualGasPrice.compareTo(maxGasPrice) > 0) {
        log.warn("Configured gas price is less than median. Median: {}, configured: {}", actualGasPrice, maxGasPrice);
        actualGasPrice = maxGasPrice;
    }
    return new TransactionParams(nonce, actualGasPrice, actualGasLimit);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:32,代码来源:ThreadsafeTransactionManager.java

示例2: decodeBitListFromBigInteger

import java.math.BigInteger; //导入方法依赖的package包/类
public static int[] decodeBitListFromBigInteger(BigInteger bits) {
    List<Integer> resultList = new ArrayList<Integer>();
    BigInteger mask = BigInteger.ONE;
    int valueCandidate = 1;
    while (mask.compareTo(bits) <= 0) {
        if ((mask.and(bits)).equals(mask)) {
            resultList.add(Integer.valueOf(valueCandidate));
        }
        valueCandidate++;
        mask = mask.shiftLeft(1);
    }

    int[] result = new int[resultList.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = resultList.get(i).intValue();
    }
    return result;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:19,代码来源:SnmpUtil.java

示例3: testSqrtHalfUp

import java.math.BigInteger; //导入方法依赖的package包/类
@GwtIncompatible // TODO
public void testSqrtHalfUp() {
  for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
    BigInteger result = BigIntegerMath.sqrt(x, HALF_UP);
    BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
    BigInteger x4 = x.shiftLeft(2);
    // sqrt(x) < result + 0.5, so 4 * x < (result + 0.5)^2 * 4
    // (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
    assertTrue(x4.compareTo(plusHalfSquared) < 0);
    BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
    // sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
    // (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
    assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) >= 0);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:16,代码来源:BigIntegerMathTest.java

示例4: ceilLog

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Compute the smallest integer that is greater than or equal to the
 * logarithm to the base 2 of the given BigInteger.
 *
 * @param a the integer
 * @return ceil[log(a)]
 */
public static int ceilLog(BigInteger a)
{
    int result = 0;
    BigInteger p = ONE;
    while (p.compareTo(a) < 0)
    {
        result++;
        p = p.shiftLeft(1);
    }
    return result;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:19,代码来源:IntegerFunctions.java

示例5: valInt

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
    if (args.get(0).isNullValue()) {
        nullValue = true; /* purecov: inspected */
        return BigInteger.ZERO; /* purecov: inspected */
    }
    int shift = args.get(1).valInt().intValue();
    if (args.get(1).isNullValue()) {
        nullValue = true;
        return BigInteger.ZERO;
    }
    nullValue = false;
    BigInteger arg1 = args.get(0).valInt();
    return shift < Long.SIZE * 8 ? arg1.shiftLeft(shift) : BigInteger.ZERO;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:16,代码来源:ItemFuncLeftShift.java

示例6: onesComplement

import java.math.BigInteger; //导入方法依赖的package包/类
public static void onesComplement(String src, String dst)
{
	BigInteger powerOfTwo = new BigInteger("1");
	powerOfTwo = powerOfTwo.shiftLeft(165);
	int label = CreateControlOp.createLabel(1);

	isLessThan(src,"ZERO",dst);
	System.out.println("/");
	System.out.printf("L[%s]\n", "ZERO");
	System.out.printf("L[%s]\n", "DIRTY");
	System.out.println("CF?4");
	binaryOp("-","ZERO",src,dst);
	System.out.println("CF+4");
	CreateMemoryOp.moveToRegister(src, dst);
	CreateMemoryOp.moveToRegister(dst, "DEC0");
	System.out.printf("N[%s] 0\n", dst);

	System.out.printf("N[CONST] %s\n", powerOfTwo.toString());

	System.out.printf(".$L%d\n", label);
	isLessThan("DEC0","CONST","EXP0");
	not("EXP0","EXP0");
	System.out.println("/");
	System.out.printf("L[%s]\n", "ZERO");
	System.out.printf("L[%s]\n", "EXP0");
	System.out.println("CF?5");
	binaryOp("-","DEC0","CONST","DEC0");
	System.out.println("CF+4");
	binaryOp("+",dst,"CONST",dst);

	binaryOp("/","CONST","TWO","CONST");
	System.out.printf("L[%s]\n", "ZERO");
	System.out.printf("L[%s]\n", "CONST");
	System.out.println("CF?1");
	System.out.printf("J[.$L%d]\n", label);
}
 
开发者ID:Christopher-Chianelli,项目名称:ccpa,代码行数:37,代码来源:CreateMathOp.java

示例7: testSqrtHalfDown

import java.math.BigInteger; //导入方法依赖的package包/类
@GwtIncompatible // TODO
public void testSqrtHalfDown() {
  for (BigInteger x : POSITIVE_BIGINTEGER_CANDIDATES) {
    BigInteger result = BigIntegerMath.sqrt(x, HALF_DOWN);
    BigInteger plusHalfSquared = result.pow(2).add(result).shiftLeft(2).add(ONE);
    BigInteger x4 = x.shiftLeft(2);
    // sqrt(x) <= result + 0.5, so 4 * x <= (result + 0.5)^2 * 4
    // (result + 0.5)^2 * 4 = (result^2 + result)*4 + 1
    assertTrue(x4.compareTo(plusHalfSquared) <= 0);
    BigInteger minusHalfSquared = result.pow(2).subtract(result).shiftLeft(2).add(ONE);
    // sqrt(x) > result - 0.5, so 4 * x > (result - 0.5)^2 * 4
    // (result - 0.5)^2 * 4 = (result^2 - result)*4 + 1
    assertTrue(result.equals(ZERO) || x4.compareTo(minusHalfSquared) > 0);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:BigIntegerMathTest.java

示例8: F2x_mul

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Algorithm 2 in "Software Implementation of Elliptic Curve Cryptography
 * Over Binary Fields", D. Hankerson, J.L. Hernandez, A. Menezes.
 */
protected static BigInteger F2x_mul(BigInteger a, BigInteger b) {
	BigInteger c = BigInteger.valueOf(0);
	for (int j = 0; j < a.bitLength(); j++) {
		if (a.testBit(j)) {
			c = c.xor(b);
		}
		b = b.shiftLeft(1);
	}

	return F2x_mod(c);
}
 
开发者ID:sheraz-n,项目名称:Cryptguard,代码行数:16,代码来源:F2m.java

示例9: Decode

import java.math.BigInteger; //导入方法依赖的package包/类
static long Decode(String idString, final String prefix) throws IllegalArgumentException {

			idString = idString.trim().toUpperCase();

			if (idString.length() != ID_LEN + prefix.length()) {
				throw new IllegalArgumentException(idString);
			}

			BigInteger idB = BigInteger.ZERO;
			for (int i = ID_LEN + prefix.length() - 1; i > prefix.length(); i--) {
				int p = alphabet.indexOf(idString.charAt(i));
				if (p >= 0) {

					idB = idB.shiftLeft(5);
					idB = idB.add(BigInteger.valueOf(p));
				}
			}
			for (int i = 64; i < 75; i++) {
				idB = idB.clearBit(i);
			}

			long id = idB.longValue();

			if (!idString.equals(Encode(id, prefix))) {
				throw new IllegalArgumentException(idString);
			}

			return id;
		}
 
开发者ID:EonTechnology,项目名称:server,代码行数:30,代码来源:Format.java

示例10: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) {

    SquareRootOfBigIntegerExample SquareRootOfBigIntegerExample =
            new SquareRootOfBigIntegerExample();
    String n = "";

    MathContext mc = new MathContext(0, RoundingMode.DOWN);
    mc = MathContext.DECIMAL32;

    BigInteger my2P100000 = new BigInteger("0");
    BigInteger two = new BigInteger("2");
    BigInteger one = new BigInteger("1");

    my2P100000 = two.shiftLeft(2000 - 1);

    System.out.println("2^2000 --  Step 1");
    System.out.println("Value of 2^2,000 " + my2P100000);
    System.out.println("");
    System.out.println("Finding the Square Root of 2^2000");

    String mys = my2P100000 + "";
    n = (mys);
    int firsttime = 0;

    BigDecimal myNumber = new BigDecimal(n);
    BigDecimal g = new BigDecimal("1");
    BigDecimal my2 = new BigDecimal("2");
    BigDecimal epsilon = new BigDecimal("0.0000000001");

    BigDecimal nByg = myNumber.divide(g, 9, BigDecimal.ROUND_FLOOR);

    //Get the value of n/g
    BigDecimal nBygPlusg = nByg.add(g);

    //Get the value of "n/g + g
    BigDecimal nBygPlusgHalf = nBygPlusg.divide(my2, 9, BigDecimal.ROUND_FLOOR);

    //Get the value of (n/g + g)/2
    BigDecimal saveg = nBygPlusgHalf;
    firsttime = 99;

    do {
      g = nBygPlusgHalf;
      nByg = myNumber.divide(g, 9, BigDecimal.ROUND_FLOOR);
      nBygPlusg = nByg.add(g);
      nBygPlusgHalf = nBygPlusg.divide(my2, 9, BigDecimal.ROUND_FLOOR);
      BigDecimal savegdiff = saveg.subtract(nBygPlusgHalf);

      if (savegdiff.compareTo(epsilon) == -1) {
        firsttime = 0;
      } else {
        saveg = nBygPlusgHalf;
      }

    } while (firsttime > 1);

    System.out.println(
            "For " + mys + "\nLength: " + mys.length() + "\nThe Square Root is " + saveg);
  }
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:60,代码来源:SquareRootOfBigIntegerExample.java

示例11: multiplyPowerOf5And2

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Multiply BigInteger by powers of 5 and 2 (i.e., 10)
 * @param value Value to multiply.
 * @param p5    Power of 5.
 * @param p2    Power of 2.
 * @return Result.
 */
private static BigInteger multiplyPowerOf5And2(final BigInteger value, final int p5, final int p2) {
    BigInteger returnValue = value;

    if (p5 != 0) {
        returnValue = returnValue.multiply(bigPowerOf5(p5));
    }

    if (p2 != 0) {
        returnValue = returnValue.shiftLeft(p2);
    }

    return returnValue;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:NumberToString.java

示例12: constructPowerOf5And2

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Construct a BigInteger power of 5 and 2 (i.e., 10)
 * @param p5    Power of 5.
 * @param p2    Power of 2.
 * @return Result.
 */
private static BigInteger constructPowerOf5And2(final int p5, final int p2) {
    BigInteger v = bigPowerOf5(p5);

    if (p2 != 0) {
        v = v.shiftLeft(p2);
    }

    return v;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:NumberToString.java

示例13: encodeZigZag64

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * @param v Signed long
 * @return Unsigned encoded long
 */
public static BigInteger encodeZigZag64(long v) {
    BigInteger origin = BigInteger.valueOf(v);
    BigInteger left = origin.shiftLeft(1);
    BigInteger right = origin.shiftRight(63);
    return left.xor(right);
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:11,代码来源:VarInt.java

示例14: modifyImplementationHook

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
protected BigInteger modifyImplementationHook(BigInteger input) {
    if (input == null) {
        input = BigInteger.ZERO;
    }
    return input.shiftLeft(shift);
}
 
开发者ID:RUB-NDS,项目名称:ModifiableVariable,代码行数:8,代码来源:BigIntegerShiftLeftModification.java

示例15: DERObjectIdentifier

import java.math.BigInteger; //导入方法依赖的package包/类
DERObjectIdentifier(
    byte[] bytes)
{
    StringBuffer objId = new StringBuffer();
    long value = 0;
    BigInteger bigValue = null;
    boolean first = true;

    for (int i = 0; i != bytes.length; i++)
    {
        int b = bytes[i] & 0xff;

        if (value <= LONG_LIMIT)
        {
            value += (b & 0x7f);
            if ((b & 0x80) == 0)             // end of number reached
            {
                if (first)
                {
                    if (value < 40)
                    {
                        objId.append('0');
                    }
                    else if (value < 80)
                    {
                        objId.append('1');
                        value -= 40;
                    }
                    else
                    {
                        objId.append('2');
                        value -= 80;
                    }
                    first = false;
                }

                objId.append('.');
                objId.append(value);
                value = 0;
            }
            else
            {
                value <<= 7;
            }
        }
        else
        {
            if (bigValue == null)
            {
                bigValue = BigInteger.valueOf(value);
            }
            bigValue = bigValue.or(BigInteger.valueOf(b & 0x7f));
            if ((b & 0x80) == 0)
            {
                if (first)
                {
                    objId.append('2');
                    bigValue = bigValue.subtract(BigInteger.valueOf(80));
                    first = false;
                }

                objId.append('.');
                objId.append(bigValue);
                bigValue = null;
                value = 0;
            }
            else
            {
                bigValue = bigValue.shiftLeft(7);
            }
        }
    }

    this.identifier = objId.toString();
    this.body = Arrays.clone(bytes);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:77,代码来源:DERObjectIdentifier.java


注:本文中的java.math.BigInteger.shiftLeft方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。