Example usage for java.math BigInteger not

List of usage examples for java.math BigInteger not

Introduction

In this page you can find the example usage for java.math BigInteger not.

Prototype

public BigInteger not() 

Source Link

Document

Returns a BigInteger whose value is (~this) .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte[] bytes = new byte[] { 0x1, 0x00, 0x00 };
    BigInteger bi = new BigInteger(bytes);
    bi = bi.not();
}

From source file:Main.java

public static void main(String[] args) {

    // assign values to bi1, bi2
    BigInteger bi1 = new BigInteger("6");
    BigInteger bi2 = new BigInteger("-6");

    // perform not operation on bi1 and bi2
    BigInteger bi3 = bi1.not();
    BigInteger bi4 = bi2.not();/*from  w w w.  j  a v a 2s  .c  om*/

    System.out.println(bi3);
    System.out.println(bi4);
}

From source file:biz.karms.sinkit.ejb.util.CIDRUtils.java

public static ImmutablePair<String, String> getStartEndAddresses(final String cidr)
        throws UnknownHostException {
    //TODO: This is silly. Refactor CIDRUtils so as to accept actual IPs as well as subnets.
    //TODO: Validate the thing before processing. Guava?
    final String fixedCIDR;
    if (!cidr.contains("/")) {
        //IPv6? Hmmm...
        if (cidr.contains(":")) {
            fixedCIDR = cidr + "/128";
        } else {//from  ww  w.  ja v a2 s  . c o  m
            fixedCIDR = cidr + "/32";
        }
    } else {
        fixedCIDR = cidr;
    }
    final int index = fixedCIDR.indexOf("/");
    final InetAddress inetAddress = InetAddress.getByName(fixedCIDR.substring(0, index));
    final int prefixLength = Integer.parseInt(fixedCIDR.substring(index + 1));

    final ByteBuffer maskBuffer;
    if (inetAddress.getAddress().length == 4) {
        maskBuffer = ByteBuffer.allocate(4).putInt(-1);
    } else {
        maskBuffer = ByteBuffer.allocate(16).putLong(-1L).putLong(-1L);
    }

    final BigInteger mask = (new BigInteger(1, maskBuffer.array())).not().shiftRight(prefixLength);
    final ByteBuffer buffer = ByteBuffer.wrap(inetAddress.getAddress());
    final BigInteger ipVal = new BigInteger(1, buffer.array());
    final BigInteger startIp = ipVal.and(mask);
    final BigInteger endIp = startIp.add(mask.not());

    return new ImmutablePair<>(String.format("%040d", startIp), String.format("%040d", endIp));
}