本文整理汇总了Java中java.math.BigInteger.setBit方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.setBit方法的具体用法?Java BigInteger.setBit怎么用?Java BigInteger.setBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.setBit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bigIntegerValue
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Returns the value of this {@code UnsignedLong} as a {@link BigInteger}.
*/
public BigInteger bigIntegerValue() {
BigInteger bigInt = BigInteger.valueOf(value & UNSIGNED_MASK);
if (value < 0) {
bigInt = bigInt.setBit(Long.SIZE - 1);
}
return bigInt;
}
示例2: getMaskedAddress
import java.math.BigInteger; //导入方法依赖的package包/类
private BigInteger getMaskedAddress(boolean one) {
BigInteger numAddress = netAddress;
int numBits;
if (isV4) {
numBits = 32 - networkMask;
} else {
numBits = 128 - networkMask;
}
for (int i = 0; i < numBits; i++) {
if (one) numAddress = numAddress.setBit(i);
else numAddress = numAddress.clearBit(i);
}
return numAddress;
}
示例3: Encode
import java.math.BigInteger; //导入方法依赖的package包/类
static String Encode(long plain, final String prefix) {
BigInteger id = BigInteger.valueOf(plain);
if (plain < 0) {
id = id.add(Format.two64);
}
BigInteger chs = BigInteger.ZERO;
BigInteger andVal = BigInteger.valueOf(0x3FF);
BigInteger tmp = id;
while (tmp.compareTo(BigInteger.ZERO) > 0) {
chs = chs.xor(tmp.and(andVal));
tmp = tmp.shiftRight(10);
}
id = id.or(chs.shiftLeft(64));
id = id.setBit(74);
StringBuilder idStr = new StringBuilder(prefix);
andVal = BigInteger.valueOf(0x1F);
for (int i = 0; i < 15; i++) {
if ((i % 5) == 0) {
idStr.append('-');
}
idStr.append(alphabet.charAt(id.and(andVal).intValue()));
id = id.shiftRight(5);
}
return idStr.toString();
}
示例4: convertHashToBigInt
import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger convertHashToBigInt(byte[] largeHash, int bitLength) {
// set first bit to 1. This ensures, that the BigInteger (in the next step) has the correct bitlength.
largeHash[0] |= 0x80;
BigInteger fdh = new BigInteger(1, largeHash);
//cut the hash to the same size as the public key
fdh = fdh.shiftRight((largeHash.length * 8) - bitLength);
// set last bit to 1 to ensure that the hash is odd. (Add 1 if the hash is even)
return fdh.setBit(0);
}
示例5: testValueOfMulPow52
import java.math.BigInteger; //导入方法依赖的package包/类
private static void testValueOfMulPow52(long value, int p5, int p2) throws Exception {
BigInteger bi = BigInteger.valueOf(value & ~LONG_SIGN_MASK);
if (value < 0) {
bi = bi.setBit(63);
}
check(biPow52(p5, p2).multiply(bi), FDBigInteger.valueOfMulPow52(value, p5, p2),
"valueOfMulPow52(" + Long.toHexString(value) + "." + p5 + "," + p2 + ")");
}
示例6: sumRights
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* 利用BigInteger对权限进行2的权的和计算
*
* @param rights
* int型权限编码数组
* @return 2的权的和
*/
public static BigInteger sumRights(int[] rights) {
BigInteger num = new BigInteger("0");
for (int i = 0; i < rights.length; i++) {
num = num.setBit(rights[i]);
}
return num;
}
示例7: calculateMqvAgreement
import java.math.BigInteger; //导入方法依赖的package包/类
private ECPoint calculateMqvAgreement(
ECDomainParameters parameters,
ECPrivateKeyParameters d1U,
ECPrivateKeyParameters d2U,
ECPublicKeyParameters Q2U,
ECPublicKeyParameters Q1V,
ECPublicKeyParameters Q2V)
{
BigInteger n = parameters.getN();
int e = (n.bitLength() + 1) / 2;
BigInteger powE = ECConstants.ONE.shiftLeft(e);
// The Q2U public key is optional
ECPoint q;
if (Q2U == null)
{
q = parameters.getG().multiply(d2U.getD());
}
else
{
q = Q2U.getQ();
}
BigInteger x = q.getX().toBigInteger();
BigInteger xBar = x.mod(powE);
BigInteger Q2UBar = xBar.setBit(e);
BigInteger s = d1U.getD().multiply(Q2UBar).mod(n).add(d2U.getD()).mod(n);
BigInteger xPrime = Q2V.getQ().getX().toBigInteger();
BigInteger xPrimeBar = xPrime.mod(powE);
BigInteger Q2VBar = xPrimeBar.setBit(e);
BigInteger hs = parameters.getH().multiply(s).mod(n);
// ECPoint p = Q1V.getQ().multiply(Q2VBar).add(Q2V.getQ()).multiply(hs);
ECPoint p = ECAlgorithms.sumOfTwoMultiplies(
Q1V.getQ(), Q2VBar.multiply(hs).mod(n), Q2V.getQ(), hs);
if (p.isInfinity())
{
throw new IllegalStateException("Infinity is not a valid agreement value for MQV");
}
return p;
}