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

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

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

BigInteger.flipBit介绍

[英]Returns a BigInteger which has the same binary representation as this but with the bit at position n flipped. The result is equivalent to this ^ pow(2, n).

Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
[中]返回一个BigInteger,它具有与此相同的二进制表示形式,但位在位置n处翻转。结果与这个^pow(2,n)等价。
实施说明:不建议使用此方法,因为当前的实施效率不高。

代码示例

代码示例来源:origin: spring-projects/spring-batch

private void updateTokenizerValidation(Object tokenizer, int index) {
  if(tokenizer != null) {
    this.tokenizerValidator = this.tokenizerValidator.flipBit(index);
  }
  else {
    this.tokenizerValidator = this.tokenizerValidator.clearBit(index);
  }
}

代码示例来源:origin: org.apache.commons/commons-math3

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

代码示例来源:origin: hcoles/pitest

@Override
 BigInteger apply(BigInteger left, BigInteger right) {
  return left.flipBit(right.intValue());
 }
}

代码示例来源:origin: com.expedia.tesla/tesla-core

public static BigInteger toUInt64(long value) {
    long lower63 = value & 0x7FFFFFFFFFFFFFFFL;
    assert (lower63 >= 0);
    BigInteger v = BigInteger.valueOf(lower63);
    if ((value & 0x8000000000000000L) != 0L) {
      return v.flipBit(63);
    }
    return v;
  }
}

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

// create 2 BigInteger objects
BigInteger bi1, bi2;

// assign value to bi1
bi1 = new BigInteger("8");//1000

// perform flipbit operation on bi1 with index 1
bi2 = bi1.flipBit(1);

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

// 2⁶⁴
private static BigInteger twoP64=BigInteger.ZERO.flipBit(64);

public static BigInteger getNumBytes()
{
 long longValue=getNumByteNative();
 BigInteger i=BigInteger.valueOf(longValue);
 if(longValue<0) i=i.add(twoP64);
 return i;
}

private native long getNumByteNative();

代码示例来源:origin: apache/servicemix-bundles

private void updateTokenizerValidation(Object tokenizer, int index) {
  if(tokenizer != null) {
    this.tokenizerValidator = this.tokenizerValidator.flipBit(index);
  }
  else {
    this.tokenizerValidator = this.tokenizerValidator.clearBit(index);
  }
}

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

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
   keyPairGenerator.initialize(2048);
   KeyPair keyPair = keyPairGenerator.generateKeyPair();
   RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
   BigInteger d = rsaPrivateKey.getPrivateExponent();
   // Flip some bits in d
   BigInteger newD = d.flipBit(29);
   // Make a new RSA private key with the modified private exponent
   RSAPrivateKeySpec newRSAPrivateSpec = new RSAPrivateKeySpec(rsaPrivateKey.getModulus(), newD);
   KeyFactory kf = KeyFactory.getInstance("RSA");
   RSAPrivateKey newPrivateKey = (RSAPrivateKey) kf.generatePrivate(newRSAPrivateSpec);

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

public static void main(String[] args) {
  int x = 2;
  int n = 4;

  Set<BigInteger> result = new LinkedHashSet<>();
  for (int j = x; j > 0; j--) {
    Set<BigInteger> a = new LinkedHashSet<>();

    for (int i = 0; i < n - j + 1; i++) {
      if (j == x) {
        a.add(BigInteger.ZERO.flipBit(i));
      } else {
        for (BigInteger num : result) {
          if (num != null && !num.testBit(i) && (i >= (n - j) || num.getLowestSetBit() >= i-1))
            a.add(num.setBit(i));
        }
      }
    }
    result = a;
  }

  String zeros = new String(new char[n]).replace("\0", "0");
  for (BigInteger i : result) {
    String binary = i.toString(2);
    System.out.println(zeros.substring(0, n - binary.length()) + binary);
  }

}

代码示例来源:origin: org.apache.commons/commons-math

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

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

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

代码示例来源:origin: io.virtdata/virtdata-lib-realer

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

代码示例来源:origin: org.apache.commons/math

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

代码示例来源:origin: harbby/presto-connectors

denominator = BigInteger.ZERO.flipBit(-k);
} else {
  numerator   = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
  denominator = BigInteger.ONE;

代码示例来源:origin: telehash/telehash-java

/**
 * Return a random hashname located with the specified bucket
 * (relative to the provided origin hashname).
 *
 * @param originHashName The origin hashname.  (i.e., your own hashname.)
 * @param bucket The bucket index.
 * @return The random hashname within the bucket.
 */
public static HashName getRandomHashName(HashName originHashName, int bucket) {
  // start with the origin hashname
  BigInteger hash = new BigInteger(1, originHashName.getBytes());
  // randomize all bits below the bucket bit
  if (bucket > 0) {
    byte[] randomBytes = Telehash.get().getCrypto().getRandomBytes(HashName.SIZE);
    BigInteger random = new BigInteger(1, randomBytes);
    BigInteger mask = BigInteger.ONE.shiftLeft(bucket).subtract(BigInteger.ONE);
    hash = hash.andNot(mask);  // chop off right part of origin
    random = random.and(mask); // chop off left part of random
    hash = hash.or(random);    // combine left-origin and right-random
  }
  // flip the bucket bit
  hash = hash.flipBit(bucket);
  // the byte array may have an extra leading byte to hold the sign bit,
  // so trim to size.
  byte[] randomHashNameBytes = Util.fixedSizeBytes(hash.toByteArray(), HashName.SIZE);
  return new HashName(randomHashNameBytes);
}

相关文章