本文整理汇总了Java中java.math.BigInteger.and方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.and方法的具体用法?Java BigInteger.and怎么用?Java BigInteger.and使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.and方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public void execute(EVMState state, Opcode opcode) throws EVMException {
EVMStack stack = state.getStack();
TraceableWord traceableWord0 = stack.pop();
TraceableWord traceableWord1 = stack.pop();
TraceTree trace1 = traceableWord0.getTrace();
TraceTree trace2 = traceableWord1.getTrace();
BigInteger element0 = new BigInteger(traceableWord0.getBytes());
BigInteger element1 = new BigInteger(traceableWord1.getBytes());
BigInteger result = element0.and(element1);
TraceableWord traceableWord = new TraceableWord(result.toByteArray());
TraceTree traceTree = buildTraceTree(opcode, traceableWord, Lists.of(traceableWord0, traceableWord1));
traceTree.addChild(trace1);
traceTree.addChild(trace2);
traceableWord.setTrace(traceTree);
stack.push(traceableWord);
}
示例2: calculateRange
import java.math.BigInteger; //导入方法依赖的package包/类
private void calculateRange(int prefix) throws UnknownHostException {
ByteBuffer maskBuffer;
int prefixSize;
if (baseAddress.getAddress().length == 4) {
maskBuffer = ByteBuffer.allocate(4).putInt(-1);
prefixSize = 4;
} else {
maskBuffer = ByteBuffer.allocate(16).putLong(-1L).putLong(-1L);
prefixSize = 16;
}
BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefix);
BigInteger ipVal = new BigInteger(1, baseAddress.getAddress());
BigInteger lowIp = ipVal.and(mask);
BigInteger hiIp = lowIp.add(mask.not());
byte[] lowIpArr = modifyArray(lowIp.toByteArray(), prefixSize);
byte[] hiIpArr = modifyArray(hiIp.toByteArray(), prefixSize);
lowAddress = InetAddress.getByAddress(lowIpArr);
highAddress = InetAddress.getByAddress(hiIpArr);
}
示例3: getIpRangeMin
import java.math.BigInteger; //导入方法依赖的package包/类
private static IpAddress getIpRangeMin(IpAddress ipAddress, int maskLength) {
BigInteger ip = ipAddress.toBigInteger();
BigInteger subnetMask = new BigInteger(
1,
new byte[]{-1, -1, -1, -1})
.shiftRight(maskLength)
.xor(new BigInteger(1, new byte[]{-1, -1, -1, -1}));
BigInteger networkAddress = ip.and(subnetMask);
if (ipAddress instanceof Ipv4Address) {
return Ipv4Address.gain(networkAddress.intValue());
} else if (ipAddress instanceof Ipv6Address) {
throw new UnsupportedAddressTypeException();
} else {
throw new IllegalArgumentException("Address acquisition failure");
}
}
示例4: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO))
val = val.and(value.mask());
if (!value.shift().equals(0))
val = val.shiftRight(value.shift());
if (value.getSigned() && val.bitLength()==(value.size()*4)) {
BigInteger complement = new BigInteger(new String(new char[value.size()]).replace("\0", "F"),16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0))
floatValue = Math.pow(value.base(), floatValue);
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f") || value.getType().toLowerCase().equals("float"))
return String.valueOf(floatValue);
return String.valueOf(Math.round(floatValue));
}
示例5: hammingDistance
import java.math.BigInteger; //导入方法依赖的package包/类
public int hammingDistance(SimHash other) {
BigInteger m = new BigInteger("1").shiftLeft(this.hashbits).subtract(
new BigInteger("1"));
BigInteger x = this.strSimHash.xor(other.strSimHash).and(m);
int tot = 0;
while (x.signum() != 0) {
tot += 1;
x = x.and(x.subtract(new BigInteger("1")));
}
return tot;
}
示例6: calculate
import java.math.BigInteger; //导入方法依赖的package包/类
private void calculate() throws UnknownHostException {
ByteBuffer maskBuffer;
int targetSize;
if (inetAddress.getAddress().length == 4) {
maskBuffer =
ByteBuffer
.allocate(4)
.putInt(-1);
targetSize = 4;
} else {
maskBuffer = ByteBuffer.allocate(16)
.putLong(-1L)
.putLong(-1L);
targetSize = 16;
}
BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefixLength);
ByteBuffer buffer = ByteBuffer.wrap(inetAddress.getAddress());
BigInteger ipVal = new BigInteger(1, buffer.array());
BigInteger startIp = ipVal.and(mask);
BigInteger endIp = startIp.add(mask.not());
byte[] startIpArr = toBytes(startIp.toByteArray(), targetSize);
byte[] endIpArr = toBytes(endIp.toByteArray(), targetSize);
this.startAddress = InetAddress.getByAddress(startIpArr);
this.endAddress = InetAddress.getByAddress(endIpArr);
}
示例7: write
import java.math.BigInteger; //导入方法依赖的package包/类
private static void write(BinaryStream stream, BigInteger v) {
_assert(v);
v = v.and(UNSIGNED_LONG_MAX_VALUE);
BigInteger i = BigInteger.valueOf(-128);
BigInteger BIX7F = BigInteger.valueOf(0x7f);
BigInteger BIX80 = BigInteger.valueOf(0x80);
while (!v.and(i).equals(BigInteger.ZERO)) {
stream.putByte(v.and(BIX7F).or(BIX80).byteValue());
v = v.shiftRight(7);
}
stream.putByte(v.byteValue());
}
示例8: calculate
import java.math.BigInteger; //导入方法依赖的package包/类
private void calculate(String cidr) throws UnknownHostException {
int index = cidr.indexOf(CIDR_RANGE_TOKEN);
String addressPart = cidr.substring(0, index);
String networkPart = cidr.substring(index + 1);
inetAddress = InetAddress.getByName(addressPart);
prefixLength = Integer.parseInt(networkPart);
ByteBuffer maskBuffer;
int targetSize;
if (inetAddress.getAddress().length == IPV4_BYTES) {
maskBuffer = ByteBuffer.allocate(IPV4_BYTES).putInt(-1);
targetSize = IPV4_BYTES;
} else {
maskBuffer = ByteBuffer.allocate(IPV6_BYTES).putLong(-1L);
targetSize = IPV6_BYTES;
}
BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefixLength);
ByteBuffer buffer = ByteBuffer.wrap(inetAddress.getAddress());
BigInteger ipValue = new BigInteger(1, buffer.array());
BigInteger startIp = ipValue.and(mask);
BigInteger endIp = startIp.add(mask.not());
byte[] startIpBytes = toBytes(startIp.toByteArray(), targetSize);
byte[] endIpBytes = toBytes(endIp.toByteArray(), targetSize);
startAddress = InetAddress.getByAddress(startIpBytes);
endAddress = InetAddress.getByAddress(endIpBytes);
}
示例9: montgomeryMultiply
import java.math.BigInteger; //导入方法依赖的package包/类
BigInteger montgomeryMultiply(BigInteger a, BigInteger b, BigInteger N,
int len, BigInteger n_prime)
throws Throwable {
BigInteger T = a.multiply(b);
BigInteger R = BigInteger.ONE.shiftLeft(len*32);
BigInteger mask = R.subtract(BigInteger.ONE);
BigInteger m = (T.and(mask)).multiply(n_prime);
m = m.and(mask); // i.e. m.mod(R)
T = T.add(m.multiply(N));
T = T.shiftRight(len*32); // i.e. T.divide(R)
if (T.compareTo(N) > 0) {
T = T.subtract(N);
}
return T;
}
示例10: valInt
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
if (args.get(0).isNullValue()) {
nullValue = true; /* purecov: inspected */
return BigInteger.ZERO; /* purecov: inspected */
}
if (args.get(1).isNullValue()) {
nullValue = true;
return BigInteger.ZERO;
}
nullValue = false;
BigInteger arg1 = args.get(0).valInt();
BigInteger arg2 = args.get(1).valInt();
return arg1.and(arg2);
}
示例11: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getType().toLowerCase().equals("s")
|| value.getType().toLowerCase().equals("string")) {
return result;
}
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}
示例12: and
import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger and( BigInteger a, BigInteger b ) {
return a.and( b );
}
示例13: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
// Do not perform transforms on non-numeric fields
if (nonNumeric(value)) {
return result;
}
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}
示例14: checkDifficultyTransitions
import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public void checkDifficultyTransitions(final StoredBlock storedPrev, final Block nextBlock,
final BlockStore blockStore) throws VerificationException, BlockStoreException {
final Block prev = storedPrev.getHeader();
// Is this supposed to be a difficulty transition point?
if (!isDifficultyTransitionPoint(storedPrev.getHeight())) {
// No ... so check the difficulty didn't actually change.
if (nextBlock.getDifficultyTarget() != prev.getDifficultyTarget())
throw new VerificationException("Unexpected change in difficulty at height " + storedPrev.getHeight() +
": " + Long.toHexString(nextBlock.getDifficultyTarget()) + " vs " +
Long.toHexString(prev.getDifficultyTarget()));
return;
}
// We need to find a block far back in the chain. It's OK that this is expensive because it only occurs every
// two weeks after the initial block chain download.
final Stopwatch watch = Stopwatch.createStarted();
Sha256Hash hash = prev.getHash();
StoredBlock cursor = null;
final int interval = this.getInterval();
for (int i = 0; i < interval; i++) {
cursor = blockStore.get(hash);
if (cursor == null) {
// This should never happen. If it does, it means we are following an incorrect or busted chain.
throw new VerificationException(
"Difficulty transition point but we did not find a way back to the last transition point. Not found: " + hash);
}
hash = cursor.getHeader().getPrevBlockHash();
}
checkState(cursor != null && isDifficultyTransitionPoint(cursor.getHeight() - 1),
"Didn't arrive at a transition point.");
watch.stop();
if (watch.elapsed(TimeUnit.MILLISECONDS) > 50)
log.info("Difficulty transition traversal took {}", watch);
Block blockIntervalAgo = cursor.getHeader();
int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds());
// Limit the adjustment step.
final int targetTimespan = this.getTargetTimespan();
if (timespan < targetTimespan / 4)
timespan = targetTimespan / 4;
if (timespan > targetTimespan * 4)
timespan = targetTimespan * 4;
BigInteger newTarget = Utils.decodeCompactBits(prev.getDifficultyTarget());
newTarget = newTarget.multiply(BigInteger.valueOf(timespan));
newTarget = newTarget.divide(BigInteger.valueOf(targetTimespan));
if (newTarget.compareTo(this.getMaxTarget()) > 0) {
log.info("Difficulty hit proof of work limit: {}", newTarget.toString(16));
newTarget = this.getMaxTarget();
}
int accuracyBytes = (int) (nextBlock.getDifficultyTarget() >>> 24) - 3;
long receivedTargetCompact = nextBlock.getDifficultyTarget();
// The calculated difficulty is to a higher precision than received, so reduce here.
BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8);
newTarget = newTarget.and(mask);
long newTargetCompact = Utils.encodeCompactBits(newTarget);
if (newTargetCompact != receivedTargetCompact)
throw new VerificationException("Network provided difficulty bits do not match what was calculated: " +
Long.toHexString(newTargetCompact) + " vs " + Long.toHexString(receivedTargetCompact));
}
示例15: transform
import java.math.BigInteger; //导入方法依赖的package包/类
public String transform(PropertyValue value, String result) {
double floatValue;
if (value.getLSB() != null) {
BigInteger val = parse(value, result);
if (!value.mask().equals(BigInteger.ZERO)) {
val = val.and(value.mask());
}
if (!value.shift().equals(0)) {
val = val.shiftRight(value.shift());
}
if (value.getSigned() && val.bitLength() == (value.size() * 4)) {
BigInteger complement =
new BigInteger(new String(new char[value.size()]).replace("\0", "F"), 16);
val = val.subtract(complement);
}
if (!objectCache.getTransformData()) {
int intValue = val.intValue();
return String.valueOf(intValue);
}
floatValue = val.doubleValue();
} else {
floatValue = Float.parseFloat(result);
}
if (!value.base().equals(0)) {
floatValue = Math.pow(value.base(), floatValue);
}
floatValue = floatValue * value.scale();
floatValue = floatValue + value.offset();
if (value.getType().toLowerCase().equals("f")
|| value.getType().toLowerCase().equals("float")) {
return String.valueOf(floatValue);
}
return String.valueOf(Math.round(floatValue));
}