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


Java BigInteger.bitCount方法代码示例

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


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

示例1: bitCount

import java.math.BigInteger; //导入方法依赖的package包/类
public static void bitCount() {
    int failCount = 0;

    for (int i=0; i<SIZE*10; i++) {
        int x = rnd.nextInt();
        BigInteger bigX = BigInteger.valueOf((long)x);
        int bit = (x < 0 ? 0 : 1);
        int tmp = x, bitCount = 0;
        for (int j=0; j<32; j++) {
            bitCount += ((tmp & 1) == bit ? 1 : 0);
            tmp >>= 1;
        }

        if (bigX.bitCount() != bitCount) {
            //System.err.println(x+": "+bitCount+", "+bigX.bitCount());
            failCount++;
        }
    }
    report("Bit Count", failCount);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:BigIntegerTest.java

示例2: bitCount

import java.math.BigInteger; //导入方法依赖的package包/类
public static void bitCount() {
    int failCount = 0;

    for (int i=0; i<SIZE*10; i++) {
        int x = random.nextInt();
        BigInteger bigX = BigInteger.valueOf((long)x);
        int bit = (x < 0 ? 0 : 1);
        int tmp = x, bitCount = 0;
        for (int j=0; j<32; j++) {
            bitCount += ((tmp & 1) == bit ? 1 : 0);
            tmp >>= 1;
        }

        if (bigX.bitCount() != bitCount) {
            //System.err.println(x+": "+bitCount+", "+bigX.bitCount());
            failCount++;
        }
    }
    report("Bit Count", failCount);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:BigIntegerTest.java

示例3: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int numOfPeople = scanner.nextInt();
    int numOfTopics = scanner.nextInt();
    BigInteger[] familiarity = new BigInteger[numOfPeople];
    int maxBitCount = 0;
    int maxScoreCount = 0;
    BigInteger score;

    for(int i=0; i<numOfPeople; i++) {
        familiarity[i] = scanner.nextBigInteger(2);
    }

    for(int i=0; i<familiarity.length-1; i++) {
        for(int j=i+1; j<=familiarity.length-1; j++) {
            score = familiarity[i].or(familiarity[j]);
            int bitCount = score.bitCount();
            if(bitCount > maxBitCount) {
                maxBitCount = bitCount;
                maxScoreCount = 1;
            } else if(bitCount == maxBitCount) {
                maxScoreCount++;
            }
        }
    }
    System.out.println(maxBitCount);
    System.out.println(maxScoreCount);
}
 
开发者ID:hell-sing,项目名称:hacker-rank,代码行数:29,代码来源:ACM_ICPC_Team.java

示例4: fromAddress

import java.math.BigInteger; //导入方法依赖的package包/类
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;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:10,代码来源:JsonRpcWhisper.java

示例5: testIsPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
@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));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:LongMathTest.java

示例6: testIsPowerOfTwo

import java.math.BigInteger; //导入方法依赖的package包/类
@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));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:IntMathTest.java

示例7: checkCanonicalSubnetAddressRange

import java.math.BigInteger; //导入方法依赖的package包/类
public static void checkCanonicalSubnetAddressRange(IpAddress lowerBound, IpAddress upperBound) {
    BigInteger size = getRangeSize(lowerBound, upperBound);
    boolean isPowersOfTwo = size.bitCount() == 1;
    if (! isPowersOfTwo) {
        throw new ValueException("サイズが2の冪になっていません.");
    }
    if (! lowerBound.toBigInteger().mod(size).equals(BigInteger.ZERO)) {
        throw new ValueException("始点アドレス(ネットワーク アドレス)がサイズの倍数になっていません.");
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:11,代码来源:IpAddress.java

示例8: isEven

import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean isEven(BigInteger num) {
    int i = num.bitCount();
    return i == 0 || num.testBit(i);
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:5,代码来源:Numbers.java


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