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


Java BigInteger.getLowestSetBit方法代码示例

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


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

示例1: ECFieldF2m

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Creates an elliptic curve characteristic 2 finite
 * field which has 2^{@code m} elements with
 * polynomial basis.
 * The reduction polynomial for this field is based
 * on {@code rp} whose i-th bit corresponds to
 * the i-th coefficient of the reduction polynomial.<p>
 * Note: A valid reduction polynomial is either a
 * trinomial (X^{@code m} + X^{@code k} + 1
 * with {@code m} &gt; {@code k} &gt;= 1) or a
 * pentanomial (X^{@code m} + X^{@code k3}
 * + X^{@code k2} + X^{@code k1} + 1 with
 * {@code m} &gt; {@code k3} &gt; {@code k2}
 * &gt; {@code k1} &gt;= 1).
 * @param m with 2^{@code m} being the number of elements.
 * @param rp the BigInteger whose i-th bit corresponds to
 * the i-th coefficient of the reduction polynomial.
 * @exception NullPointerException if {@code rp} is null.
 * @exception IllegalArgumentException if {@code m}
 * is not positive, or {@code rp} does not represent
 * a valid reduction polynomial.
 */
public ECFieldF2m(int m, BigInteger rp) {
    // check m and rp
    this.m = m;
    this.rp = rp;
    if (m <= 0) {
        throw new IllegalArgumentException("m is not positive");
    }
    int bitCount = this.rp.bitCount();
    if (!this.rp.testBit(0) || !this.rp.testBit(m) ||
        ((bitCount != 3) && (bitCount != 5))) {
        throw new IllegalArgumentException
            ("rp does not represent a valid reduction polynomial");
    }
    // convert rp into ks
    BigInteger temp = this.rp.clearBit(0).clearBit(m);
    this.ks = new int[bitCount-2];
    for (int i = this.ks.length-1; i >= 0; i--) {
        int index = temp.getLowestSetBit();
        this.ks[i] = index;
        temp = temp.clearBit(index);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:ECFieldF2m.java

示例2: lucasSequence

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger[] lucasSequence(BigInteger p, BigInteger P, BigInteger Q, BigInteger k) {
   int n = k.bitLength();
   int s = k.getLowestSetBit();

   BigInteger Uh = BigInteger.ONE;
   BigInteger Vl = TWO;
   BigInteger Vh = P;
   BigInteger Ql = BigInteger.ONE;
   BigInteger Qh = BigInteger.ONE;

   for (int j = n - 1; j >= s + 1; --j) {
      Ql = Ql.multiply(Qh).mod(p);

      if (k.testBit(j)) {
         Qh = Ql.multiply(Q).mod(p);
         Uh = Uh.multiply(Vh).mod(p);
         Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
         Vh = Vh.multiply(Vh).subtract(Qh.shiftLeft(1)).mod(p);
      } else {
         Qh = Ql;
         Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
         Vh = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
         Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
      }
   }

   Ql = Ql.multiply(Qh).mod(p);
   Qh = Ql.multiply(Q).mod(p);
   Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
   Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
   Ql = Ql.multiply(Qh).mod(p);

   for (int j = 1; j <= s; ++j) {
      Uh = Uh.multiply(Vl).mod(p);
      Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
      Ql = Ql.multiply(Ql).mod(p);
   }

   return new BigInteger[] { Uh, Vl };
}
 
开发者ID:mithrilcoin-io,项目名称:EosCommander,代码行数:41,代码来源:EcFieldElement.java

示例3: bigToDouble

import java.math.BigInteger; //导入方法依赖的package包/类
static double bigToDouble(BigInteger x) {
  // This is an extremely fast implementation of BigInteger.doubleValue().  JDK patch pending.
  BigInteger absX = x.abs();
  int exponent = absX.bitLength() - 1;
  // exponent == floor(log2(abs(x)))
  if (exponent < Long.SIZE - 1) {
    return x.longValue();
  } else if (exponent > MAX_EXPONENT) {
    return x.signum() * POSITIVE_INFINITY;
  }

  /*
   * We need the top SIGNIFICAND_BITS + 1 bits, including the "implicit" one bit. To make
   * rounding easier, we pick out the top SIGNIFICAND_BITS + 2 bits, so we have one to help us
   * round up or down. twiceSignifFloor will contain the top SIGNIFICAND_BITS + 2 bits, and
   * signifFloor the top SIGNIFICAND_BITS + 1.
   *
   * It helps to consider the real number signif = absX * 2^(SIGNIFICAND_BITS - exponent).
   */
  int shift = exponent - SIGNIFICAND_BITS - 1;
  long twiceSignifFloor = absX.shiftRight(shift).longValue();
  long signifFloor = twiceSignifFloor >> 1;
  signifFloor &= SIGNIFICAND_MASK; // remove the implied bit

  /*
   * We round up if either the fractional part of signif is strictly greater than 0.5 (which is
   * true if the 0.5 bit is set and any lower bit is set), or if the fractional part of signif is
   * >= 0.5 and signifFloor is odd (which is true if both the 0.5 bit and the 1 bit are set).
   */
  boolean increment = (twiceSignifFloor & 1) != 0
      && ((signifFloor & 1) != 0 || absX.getLowestSetBit() < shift);
  long signifRounded = increment ? signifFloor + 1 : signifFloor;
  long bits = (long) ((exponent + EXPONENT_BIAS)) << SIGNIFICAND_BITS;
  bits += signifRounded;
  /*
   * If signifRounded == 2^53, we'd need to set all of the significand bits to zero and add 1 to
   * the exponent. This is exactly the behavior we get from just adding signifRounded to bits
   * directly.  If the exponent is MAX_DOUBLE_EXPONENT, we round up (correctly) to
   * Double.POSITIVE_INFINITY.
   */
  bits |= x.signum() & SIGN_MASK;
  return longBitsToDouble(bits);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:44,代码来源:DoubleUtils.java

示例4: isPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Returns {@code true} if {@code x} represents a power of two.
 */
public static boolean isPowerOfTwo(BigInteger x) {
  checkNotNull(x);
  return x.signum() > 0 && x.getLowestSetBit() == x.bitLength() - 1;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:8,代码来源:BigIntegerMath.java

示例5: lucasSequence

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger[] lucasSequence(
    BigInteger  p,
    BigInteger  P,
    BigInteger  Q,
    BigInteger  k)
{
    int n = k.bitLength();
    int s = k.getLowestSetBit();

    BigInteger Uh = ECConstants.ONE;
    BigInteger Vl = ECConstants.TWO;
    BigInteger Vh = P;
    BigInteger Ql = ECConstants.ONE;
    BigInteger Qh = ECConstants.ONE;

    for (int j = n - 1; j >= s + 1; --j)
    {
        Ql = Ql.multiply(Qh).mod(p);

        if (k.testBit(j))
        {
            Qh = Ql.multiply(Q).mod(p);
            Uh = Uh.multiply(Vh).mod(p);
            Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
            Vh = Vh.multiply(Vh).subtract(Qh.shiftLeft(1)).mod(p);
        }
        else
        {
            Qh = Ql;
            Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
            Vh = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
            Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
        }
    }

    Ql = Ql.multiply(Qh).mod(p);
    Qh = Ql.multiply(Q).mod(p);
    Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
    Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
    Ql = Ql.multiply(Qh).mod(p);

    for (int j = 1; j <= s; ++j)
    {
        Uh = Uh.multiply(Vl).mod(p);
        Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
        Ql = Ql.multiply(Ql).mod(p);
    }

    return new BigInteger[]{ Uh, Vl };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:51,代码来源:ECFieldElement.java

示例6: bigToDouble

import java.math.BigInteger; //导入方法依赖的package包/类
static double bigToDouble(BigInteger x) {
  // This is an extremely fast implementation of BigInteger.doubleValue(). JDK patch pending.
  BigInteger absX = x.abs();
  int exponent = absX.bitLength() - 1;
  // exponent == floor(log2(abs(x)))
  if (exponent < Long.SIZE - 1) {
    return x.longValue();
  } else if (exponent > MAX_EXPONENT) {
    return x.signum() * POSITIVE_INFINITY;
  }

  /*
   * We need the top SIGNIFICAND_BITS + 1 bits, including the "implicit" one bit. To make rounding
   * easier, we pick out the top SIGNIFICAND_BITS + 2 bits, so we have one to help us round up or
   * down. twiceSignifFloor will contain the top SIGNIFICAND_BITS + 2 bits, and signifFloor the
   * top SIGNIFICAND_BITS + 1.
   *
   * It helps to consider the real number signif = absX * 2^(SIGNIFICAND_BITS - exponent).
   */
  int shift = exponent - SIGNIFICAND_BITS - 1;
  long twiceSignifFloor = absX.shiftRight(shift).longValue();
  long signifFloor = twiceSignifFloor >> 1;
  signifFloor &= SIGNIFICAND_MASK; // remove the implied bit

  /*
   * We round up if either the fractional part of signif is strictly greater than 0.5 (which is
   * true if the 0.5 bit is set and any lower bit is set), or if the fractional part of signif is
   * >= 0.5 and signifFloor is odd (which is true if both the 0.5 bit and the 1 bit are set).
   */
  boolean increment =
      (twiceSignifFloor & 1) != 0 && ((signifFloor & 1) != 0 || absX.getLowestSetBit() < shift);
  long signifRounded = increment ? signifFloor + 1 : signifFloor;
  long bits = (long) ((exponent + EXPONENT_BIAS)) << SIGNIFICAND_BITS;
  bits += signifRounded;
  /*
   * If signifRounded == 2^53, we'd need to set all of the significand bits to zero and add 1 to
   * the exponent. This is exactly the behavior we get from just adding signifRounded to bits
   * directly. If the exponent is MAX_DOUBLE_EXPONENT, we round up (correctly) to
   * Double.POSITIVE_INFINITY.
   */
  bits |= x.signum() & SIGN_MASK;
  return longBitsToDouble(bits);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:44,代码来源:DoubleUtils.java

示例7: FastLucasSequence

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger[] FastLucasSequence(final BigInteger p, final BigInteger P, final BigInteger Q,
		final BigInteger k) {
	final int n = k.bitLength();
	final int s = k.getLowestSetBit();

	BigInteger Uh = BigInteger.ONE;
	BigInteger Vl = BigInteger.valueOf(2);
	BigInteger Vh = P;
	BigInteger Ql = BigInteger.ONE;
	BigInteger Qh = BigInteger.ONE;

	for (int j = n - 1; j >= (s + 1); --j) {
		Ql = (Ql.multiply(Qh)).mod(p);

		if (k.testBit(j)) {
			Qh = (Ql.multiply(Q)).mod(p);
			Uh = (Uh.multiply(Vh)).mod(p);
			Vl = (Vh.multiply(Vl).subtract(P.multiply(Ql))).mod(p);
			Vh = ((Vh.multiply(Vh)).subtract((Qh.shiftLeft(1)))).mod(p);
		} else {
			Qh = Ql;
			Uh = (Uh.multiply(Vl).subtract(Ql)).mod(p);
			Vh = (Vh.multiply(Vl).subtract(P.multiply(Ql))).mod(p);
			Vl = ((Vl.multiply(Vl)).subtract((Ql.shiftLeft(1)))).mod(p);
		}
	}

	Ql = Ql.multiply(Qh).mod(p);
	Qh = Ql.multiply(Q).mod(p);
	Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
	Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
	Ql = Ql.multiply(Qh).mod(p);

	for (int j = 1; j <= s; ++j) {
		Uh = Uh.multiply(Vl).multiply(p);
		Vl = ((Vl.multiply(Vl)).subtract((Ql.shiftLeft(1)))).mod(p);
		Ql = (Ql.multiply(Ql)).mod(p);
	}

	return new BigInteger[] { Uh, Vl };
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:42,代码来源:ECFieldElement.java

示例8: isEven

import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean isEven(final BigInteger number) {
	return number.getLowestSetBit() != 0;
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:4,代码来源:ECPoint.java


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