List of usage examples for java.math BigInteger shiftRight
public BigInteger shiftRight(int n)
From source file:net.spfbl.whois.SubnetIPv6.java
public static String getPreviousIPv6(String ip) { if (ip == null) { return null; } else if (SubnetIPv6.isValidIPv6(ip)) { BigInteger address = new BigInteger(1, address(ip)); if (address.equals(ADDRESS_MIN)) { return null; } else {//w w w . jav a2s. c om address = address.subtract(ADDRESS_UNIT); int p8 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p7 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p6 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p5 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p4 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p3 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p2 = address.and(ADDRESS_OCTET).intValue(); address = address.shiftRight(16); int p1 = address.and(ADDRESS_OCTET).intValue(); return Integer.toHexString(p1) + ":" + Integer.toHexString(p2) + ":" + Integer.toHexString(p3) + ":" + Integer.toHexString(p4) + ":" + Integer.toHexString(p5) + ":" + Integer.toHexString(p6) + ":" + Integer.toHexString(p7) + ":" + Integer.toHexString(p8); } } else { return null; } }
From source file:org.apache.cassandra.utils.FBUtilities.java
/** * Given two bit arrays represented as BigIntegers, containing the given * number of significant bits, calculate a midpoint. * * @param left The left point.//from ww w . j a v a 2 s .c o m * @param right The right point. * @param sigbits The number of bits in the points that are significant. * @return A midpoint that will compare bitwise halfway between the params, and * a boolean representing whether a non-zero lsbit remainder was generated. */ public static Pair<BigInteger, Boolean> midpoint(BigInteger left, BigInteger right, int sigbits) { BigInteger midpoint; boolean remainder; if (left.compareTo(right) < 0) { BigInteger sum = left.add(right); remainder = sum.testBit(0); midpoint = sum.shiftRight(1); } else { BigInteger max = TWO.pow(sigbits); // wrapping case BigInteger distance = max.add(right).subtract(left); remainder = distance.testBit(0); midpoint = distance.shiftRight(1).add(left).mod(max); } return new Pair<BigInteger, Boolean>(midpoint, remainder); }
From source file:org.i3xx.step.mongo.core.util.IdGen.java
/** * Gets a 128 bit IdRep from a BigInteger * //from ww w.j a v a 2s . c o m * @return The IdRep object */ public static final IdRep fromBigInteger(BigInteger ui) { UUID uuid = new UUID(ui.shiftRight(64).longValue(), ui.longValue()); return new JavaIdRep(uuid); }
From source file:org.voltdb.hadoop.Digester.java
/** * Generate a {@code UUID} representation of the MD5 digest for the given content. This is possible because MD5 * digests and UUIDs are both 128 bit long * * @param aContent/*ww w .j a va 2 s . c o m*/ * a content {@code String} * @return a {@code UUID} representation of the computed MD5 digest * @throws DigesterException * upon failed cryptographic operation */ public final static UUID digestMD5asUUID(String aContent) throws DigestException { if (aContent == null) return null; BigInteger bi = digestMD5asBigInteger(aContent); return new UUID(bi.shiftRight(64).longValue(), bi.and(LSB_MASK).longValue()); }