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

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

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

BigInteger.and介绍

[英]Returns a BigInteger whose value is this & value.

Implementation Note: Usage of this method is not recommended as the current implementation is not efficient.
[中]返回一个BigInteger,其值为&value。
实施说明:不建议使用此方法,因为当前的实施效率不高。

代码示例

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

@Override
public boolean matches(InetSocketAddress remoteAddress) {
  final InetAddress inetAddress = remoteAddress.getAddress();
  if (inetAddress instanceof Inet6Address) {
    BigInteger ipAddress = ipToInt((Inet6Address) inetAddress);
    return ipAddress.and(subnetMask).equals(networkAddress);
  }
  return false;
}

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

private Ip6SubnetFilterRule(Inet6Address ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
  if (cidrPrefix < 0 || cidrPrefix > 128) {
    throw new IllegalArgumentException(String.format("IPv6 requires the subnet prefix to be in range of " +
                              "[0,128]. The prefix was: %d", cidrPrefix));
  }
  subnetMask = prefixToSubnetMask(cidrPrefix);
  networkAddress = ipToInt(ipAddress).and(subnetMask);
  this.ruleType = ruleType;
}

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

@Override
public boolean matches(InetSocketAddress remoteAddress) {
  final InetAddress inetAddress = remoteAddress.getAddress();
  if (inetAddress instanceof Inet6Address) {
    BigInteger ipAddress = ipToInt((Inet6Address) inetAddress);
    return ipAddress.and(subnetMask).equals(networkAddress);
  }
  return false;
}

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

public ExpandedDouble(long rawBits) {
  int biasedExp = (int) (rawBits >> 52);
  if (biasedExp == 0) {
    // sub-normal numbers
    BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);
    int expAdj = 64 - frac.bitLength();
    _significand = frac.shiftLeft(expAdj);
    _binaryExponent = (biasedExp & 0x07FF) - 1023 - expAdj;
  } else {
    _significand = getFrac(rawBits);
    _binaryExponent = (biasedExp & 0x07FF) - 1023;
  }
}

代码示例来源:origin: plutext/docx4j

public ExpandedDouble(long rawBits) {
  int biasedExp = (int) (rawBits >> 52);
  if (biasedExp == 0) {
    // sub-normal numbers
    BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);
    int expAdj = 64 - frac.bitLength();
    _significand = frac.shiftLeft(expAdj);
    _binaryExponent = (biasedExp & 0x07FF) - 1023 - expAdj;
  } else {
    BigInteger frac = getFrac(rawBits);
    _significand = frac;
    _binaryExponent = (biasedExp & 0x07FF) - 1023;
  }
}

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

private Ip6SubnetFilterRule(Inet6Address ipAddress, int cidrPrefix, IpFilterRuleType ruleType) {
  if (cidrPrefix < 0 || cidrPrefix > 128) {
    throw new IllegalArgumentException(String.format("IPv6 requires the subnet prefix to be in range of " +
                              "[0,128]. The prefix was: %d", cidrPrefix));
  }
  subnetMask = prefixToSubnetMask(cidrPrefix);
  networkAddress = ipToInt(ipAddress).and(subnetMask);
  this.ruleType = ruleType;
}

代码示例来源:origin: Graylog2/graylog2-server

private void calculate() throws UnknownHostException {
  final int targetSize;
  final BigInteger mask;
  if (inetAddress.getAddress().length == 4) {
    targetSize = 4;
    mask = (new BigInteger(1, MASK_IPV4)).not().shiftRight(prefixLength);
  } else {
    targetSize = 16;
    mask = (new BigInteger(1, MASK_IPV6)).not().shiftRight(prefixLength);
  }
  final BigInteger ipVal = new BigInteger(1, inetAddress.getAddress());
  final BigInteger startIp = ipVal.and(mask);
  final BigInteger endIp = startIp.add(mask.not());
  final byte[] startIpArr = toBytes(startIp.toByteArray(), targetSize);
  final byte[] endIpArr = toBytes(endIp.toByteArray(), targetSize);
  this.startAddress = InetAddress.getByAddress(startIpArr);
  this.endAddress = InetAddress.getByAddress(endIpArr);
}

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

public void testIsPowerOfTwo() {
 for (BigInteger x : ALL_BIGINTEGER_CANDIDATES) {
  // Checks for a single bit set.
  boolean expected = x.signum() > 0 & x.and(x.subtract(ONE)).equals(ZERO);
  assertEquals(expected, BigIntegerMath.isPowerOfTwo(x));
 }
}

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

public DataWord sMod(DataWord word) {
  if (word.isZero()) {
    return ZERO;
  }
  BigInteger result = sValue().abs().mod(word.sValue().abs());
  result = (sValue().signum() == -1) ? result.negate() : result;
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

/**
 * Shift left, both this and input arg are treated as unsigned
 * @param arg
 * @return this << arg
 */
public DataWord shiftLeft(DataWord arg) {
  if (arg.value().compareTo(BigInteger.valueOf(MAX_POW)) >= 0) {
    return DataWord.ZERO;
  }
  
  BigInteger result = value().shiftLeft(arg.intValueSafe());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

/**
 * Shift right, both this and input arg are treated as unsigned
 * @param arg
 * @return this >> arg
 */
public DataWord shiftRight(DataWord arg) {
  if (arg.value().compareTo(BigInteger.valueOf(MAX_POW)) >= 0) {
    return DataWord.ZERO;
  }
  BigInteger result = value().shiftRight(arg.intValueSafe());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

代码示例来源:origin: io.netty/netty

protected CIDR6(Inet6Address newaddress, int newmask) {
  cidrMask = newmask;
  addressBigInt = ipv6AddressToBigInteger(newaddress);
  BigInteger mask = ipv6CidrMaskToMask(newmask);
  try {
    addressBigInt = addressBigInt.and(mask);
    baseAddress = bigIntToIPv6Address(addressBigInt);
  } catch (UnknownHostException e) {
    // this should never happen.
  }
  addressEndBigInt = addressBigInt.add(ipv6CidrMaskToBaseAddress(cidrMask)).subtract(BigInteger.ONE);
}

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

public DataWord add2(DataWord word) {
  BigInteger result = value().add(word.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord mul(DataWord word) {
  BigInteger result = value().multiply(word.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord sub(DataWord word) {
  BigInteger result = value().subtract(word.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord addmod(DataWord word1, DataWord word2) {
  if (word2.isZero()) {
    return ZERO;
  }
  BigInteger result = value().add(word1.value()).mod(word2.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord sDiv(DataWord word) {
  if (word.isZero()) {
    return ZERO;
  }
  BigInteger result = sValue().divide(word.sValue());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord div(DataWord word) {
  if (word.isZero()) {
    return ZERO;
  }
  BigInteger result = value().divide(word.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord mod(DataWord word) {
  if (word.isZero()) {
    return ZERO;
  }
  BigInteger result = value().mod(word.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

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

public DataWord mulmod(DataWord word1, DataWord word2) {
  if (this.isZero() || word1.isZero() || word2.isZero()) {
    return ZERO;
  }
  BigInteger result = value().multiply(word1.value()).mod(word2.value());
  return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}

相关文章