本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
}
示例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));
}
}
示例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("始点アドレス(ネットワーク アドレス)がサイズの倍数になっていません.");
}
}
示例8: isEven
import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean isEven(BigInteger num) {
int i = num.bitCount();
return i == 0 || num.testBit(i);
}