java.math.BigInteger.bitCount()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中java.math.BigInteger.bitCount()方法的一些代码示例,展示了BigInteger.bitCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.bitCount()方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:bitCount

BigInteger.bitCount介绍

[英]One plus the bitCount of this BigInteger. Zeros means unitialized.
[中]一加上这个大整数的位计数。零表示单位化。

代码示例

代码示例来源:origin: web3j/web3j

private static boolean isValidBitCount(int mBitSize, int nBitSize, BigInteger value) {
  return value.bitCount() <= mBitSize + nBitSize;
}

代码示例来源:origin: ethereum/ethereumj

private String fromAddress(String s) {
  if (s == null) return null;
  s = del0X(s);
  BigInteger i = new BigInteger(s, 16);
  if (i.bitCount() > 0) {
    return s;
  }
  return null;
}

代码示例来源:origin: alibaba/druid

return ((BigInteger) paramValue).bitCount();
BigDecimal decimal = (BigDecimal) paramValue;
BigInteger bigInt = decimal.setScale(0,  BigDecimal.ROUND_HALF_UP).toBigInteger();
return bigInt.bitCount();

代码示例来源:origin: google/guava

@GwtIncompatible // java.math.BigInteger
public void testIsPowerOfTwo() {
 for (int x : ALL_INTEGER_CANDIDATES) {
  // Checks for a single bit set.
  BigInteger bigX = BigInteger.valueOf(x);
  boolean expected = (bigX.signum() > 0) && (bigX.bitCount() == 1);
  assertEquals(expected, IntMath.isPowerOfTwo(x));
 }
}

代码示例来源:origin: google/guava

@GwtIncompatible // java.math.BigInteger
public void testIsPowerOfTwo() {
 for (long x : ALL_LONG_CANDIDATES) {
  // Checks for a single bit set.
  BigInteger bigX = BigInteger.valueOf(x);
  boolean expected = (bigX.signum() > 0) && (bigX.bitCount() == 1);
  assertEquals(expected, LongMath.isPowerOfTwo(x));
 }
}

代码示例来源:origin: robovm/robovm

int rp_bc = this.rp.bitCount();
if ((this.rp.bitLength() != (m+1)) ||
  (rp_bc != TPB_LEN && rp_bc != PPB_LEN) ||

代码示例来源:origin: com.alibaba/druid

return ((BigInteger) paramValue).bitCount();
BigDecimal decimal = (BigDecimal) paramValue;
BigInteger bigInt = decimal.setScale(0,  BigDecimal.ROUND_HALF_UP).toBigInteger();
return bigInt.bitCount();

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  String a = "1001101111101011011100101100100110111011111011000100111100111110111101011011011100111001100011111010";
  int x = new BigInteger(a, 2).bitCount(); 
  System.out.println(x);
}

代码示例来源:origin: stackoverflow.com

private static final BigInteger FOUR = new BigInteger("4");

public boolean binaryStringIsOK(final String input)
{
  final BigInteger b;

  try {
    b = new BigInteger(inputString, 2);
    return b.mod(FOUR).equals(BigInteger.ZERO)
      && b.bitCount() >= 3;
  } catch (NumberException ignored) {
    return false;
  }
}

代码示例来源:origin: stackoverflow.com

import java.math.BigInteger;

public class BigIntegerTest {
  public static void main(String[] args) {
    BigInteger b1 = new BigInteger("200000000000000000000000000000000001");
    BigInteger b2 = new BigInteger("400000000000000000000000000000000000");

    System.out.println(b1.multiply(b2));
    System.out.println(b1.bitCount());
    System.out.println(b1.pow(13));
  }
}

代码示例来源:origin: stackoverflow.com

public static int numberOfMatchingOnes(String a, String b) {
  BigInteger aNumber = new BigInteger(a, 16);
  BigInteger bNumber = new BigInteger(b, 16);

  return aNumber.xor(bNumber).bitCount();
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

public static int getNafWeight(BigInteger k)
{
  if (k.signum() == 0)
  {
    return 0;
  }
  BigInteger _3k = k.shiftLeft(1).add(k);
  BigInteger diff = _3k.xor(k);
  return diff.bitCount();
}

代码示例来源:origin: io.github.myui/hivemall

/**
 * Count bits that both bits are 1.
 */
public IntWritable evaluate(String a, String b) {
  BigInteger ai = new BigInteger(a);
  BigInteger bi = new BigInteger(b);
  BigInteger innerProduct = ai.and(bi);
  return val(innerProduct.bitCount());
}

代码示例来源:origin: ripple-unmaintained/ripple-lib-java

public static int getNafWeight(BigInteger k)
{
  if (k.signum() == 0)
  {
    return 0;
  }
  BigInteger _3k = k.shiftLeft(1).add(k);
  BigInteger diff = _3k.xor(k);
  return diff.bitCount();
}

代码示例来源:origin: ggp-org/ggp-base

@Override
public int hashCode()
{
  byte[] bytes = name.toString().getBytes();
  BigInteger bigInt = new BigInteger(bytes);
  int val = bigInt.bitCount()+bigInt.intValue();
  return val+idx;
}

代码示例来源:origin: com.madgag.spongycastle/core

public static int getNafWeight(BigInteger k)
{
  if (k.signum() == 0)
  {
    return 0;
  }
  BigInteger _3k = k.shiftLeft(1).add(k);
  BigInteger diff = _3k.xor(k);
  return diff.bitCount();
}

代码示例来源:origin: io.github.myui/hivemall

public static int hammingDistance(final BigInteger a, final BigInteger b) {
  BigInteger xor = a.xor(b);
  return xor.bitCount();
}

代码示例来源:origin: actiontech/dble

@Override
public BigInteger valInt() {
  BigInteger value = args.get(0).valInt();
  if ((nullValue = args.get(0).isNullValue()))
    return BigInteger.ZERO; /* purecov: inspected */
  return BigInteger.valueOf(value.bitCount());
}

代码示例来源:origin: org.apache.jena/jena-core

static int bitCount( final int i )
{
  return java.math.BigInteger.valueOf(i).bitCount();
}

代码示例来源:origin: com.google.guava/guava-tests

@GwtIncompatible // java.math.BigInteger
public void testIsPowerOfTwo() {
 for (long x : ALL_LONG_CANDIDATES) {
  // Checks for a single bit set.
  BigInteger bigX = BigInteger.valueOf(x);
  boolean expected = (bigX.signum() > 0) && (bigX.bitCount() == 1);
  assertEquals(expected, LongMath.isPowerOfTwo(x));
 }
}

相关文章