private static BigInteger ipv6CidrMaskToMask(int cidrMask) { return BigInteger.ONE.shiftLeft(128 - cidrMask).subtract(BigInteger.ONE).not(); }
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); }
private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative) { final byte[] remainder = new byte[length - 1]; System.arraycopy(buffer, offset + 1, remainder, 0, length - 1); BigInteger val = new BigInteger(remainder); if (negative) { // 2's complement val = val.add(BigInteger.valueOf(-1)).not(); } if (val.bitLength() > 63) { throw new IllegalArgumentException("At offset " + offset + ", " + length + " byte binary number" + " exceeds maximum signed long" + " value"); } return negative ? -val.longValue() : val.longValue(); }
private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative) { final byte[] remainder = new byte[length - 1]; System.arraycopy(buffer, offset + 1, remainder, 0, length - 1); BigInteger val = new BigInteger(remainder); if (negative) { // 2's complement val = val.add(BigInteger.valueOf(-1)).not(); } if (val.bitLength() > 63) { throw new IllegalArgumentException(String.format( "At offset %d, %d byte binary number exceeds maximum signed long value", offset, length)); } return negative ? -val.longValue() : val.longValue(); }
protected Number bitwiseNegateImpl(Number left) { return toBigInteger(left).not(); }
public static Object bitwiseNegate(Object value) { if (value instanceof Integer) { Integer number = (Integer) value; return ~number; } if (value instanceof Long) { Long number = (Long) value; return ~number; } if (value instanceof BigInteger) { return ((BigInteger) value).not(); } if (value instanceof String) { // value is a regular expression. return StringGroovyMethods.bitwiseNegate((CharSequence)value.toString()); } if (value instanceof GString) { // value is a regular expression. return StringGroovyMethods.bitwiseNegate((CharSequence)value.toString()); } if (value instanceof ArrayList) { // value is a list. List newlist = new ArrayList(); for (Object o : ((ArrayList) value)) { newlist.add(bitwiseNegate(o)); } return newlist; } return invokeMethod(value, "bitwiseNegate", EMPTY_ARGS); }
/** @see BigInteger#andNot(BigInteger) */ static BigInteger andNot(BigInteger val, BigInteger that) { if (that.sign == 0 ) { return val; } if (val.sign == 0) { return BigInteger.ZERO; } if (val.equals(BigInteger.MINUS_ONE)) { return that.not(); } if (that.equals(BigInteger.MINUS_ONE)){ return BigInteger.ZERO; } //if val == that, return 0 if (val.sign > 0) { if (that.sign > 0) { return andNotPositive(val, that); } else { return andNotPositiveNegative(val, that); } } else { if (that.sign > 0) { return andNotNegativePositive(val, that); } else { return andNotNegative(val, that); } } }
@Override BigInteger apply(BigInteger left, BigInteger right) { return left.not(); } }
/** rb_big_neg * */ @Override public IRubyObject op_neg(ThreadContext context) { return RubyBignum.newBignum(context.runtime, value.not()); }
/** rb_big_neg * */ @Override public IRubyObject op_neg(ThreadContext context) { return RubyBignum.newBignum(context.runtime, value.not()); }
static boolean testRange(BigInteger lowerValue, BigInteger upperValue, BigInteger finalUpperValue, int bitCount, int divisionPrefixLen) { BigInteger networkMask = AddressDivisionGroupingBase.ALL_ONES.shiftLeft(bitCount - divisionPrefixLen); BigInteger hostMask = networkMask.not(); return testRange(lowerValue, upperValue, finalUpperValue, networkMask, hostMask); }
@Override public String encode(BigInteger value) { checkNotNull(value, "Null values are not allowed"); return bigIntEncoder.encode(value.not()); }
@Override public BigInteger decode(String value) throws TypeDecodingException { return bigIntEncoder.decode(value).not(); } }
/** * * @return */ public Level not() { return new Level(n.not()); } }
/** rb_big_neg * */ @JRubyMethod(name = "~") public IRubyObject op_neg() { return RubyBignum.newBignum(getRuntime(), value.not()); }
public static Object bitNegate(Object value) { int type = getNumericType(value); switch(type) { case BIGDEC: case BIGINT: return bigIntValue(value).not(); default: return newInteger(type, ~longValue(value)); } }
public static Object bitNegate( Object value ) { int type = getNumericType(value); switch ( type ) { case BIGDEC: case BIGINT: return bigIntValue(value).not(); default: return newInteger( type, ~longValue(value) ); } } }
public static Object bitNegate(Object value) { int type = getNumericType(value); switch(type) { case BIGDEC: case BIGINT: return bigIntValue(value).not(); default: return newInteger(type, ~longValue(value)); } }
public static Object bitNegate(Object value) { int type = getNumericType(value); switch (type) { case BIGDEC: case BIGINT: return bigIntValue(value).not(); default: return newInteger(type, ~longValue(value)); } } }