Example usage for java.math BigInteger longValue

List of usage examples for java.math BigInteger longValue

Introduction

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

Prototype

public long longValue() 

Source Link

Document

Converts this BigInteger to a long .

Usage

From source file:Main.java

public static void main(String[] args) {

    BigInteger bi1 = new BigInteger("-123");
    BigInteger bi2 = new BigInteger("987654321");

    // assign the long values of bi1, bi2 to l1, l2
    Long l1 = bi1.longValue();
    Long l2 = bi2.longValue();/*www.jav a2 s. c  om*/

    System.out.println(l1);
    System.out.println(l2);
}

From source file:Main.java

public static int VarIntLength(long value) {
    if (value < 253)
        return 1;
    if (value < 65536)
        return 3;
    BigInteger bytes5 = new BigInteger("4294967296");
    if (value < bytes5.longValue())
        return 5;
    return 9;//from ww  w.ja  v  a  2  s .c o m
}

From source file:Main.java

public static <P extends Collection<BigInteger>> List<Long> convertAllElementsToLong(P bigIntegers) {
    if (bigIntegers == null) {
        return null;
    }//from  www.j  a v a2s  . c o  m
    try {
        ArrayList<Long> results = new ArrayList<Long>();
        for (BigInteger bigInteger : bigIntegers) {
            results.add(bigInteger.longValue());
        }
        return results;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.i3xx.step.mongo.core.util.IdGen.java

/**
 * Gets a 128 bit IdRep from a BigInteger
 * //from ww w .  ja  va  2  s  .  co 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:nl.sidn.pcap.PcapReaderUtil.java

public static long convertUnsignedInt(byte[] data, int offset) {
    byte[] target = new byte[4];
    System.arraycopy(data, offset, target, 0, target.length);

    BigInteger placeholder = new BigInteger(1, target);
    return placeholder.longValue();
}

From source file:Main.java

public static Date toDate(Instant instant) {
    BigInteger milis = BigInteger.valueOf(instant.getEpochSecond()).multiply(BigInteger.valueOf(1000));
    milis = milis.add(BigInteger.valueOf(instant.getNano()).divide(BigInteger.valueOf(1_000_000)));
    return new Date(milis.longValue());
}

From source file:de.upb.wdqa.wdvd.geolocation.GeolocationDatabase.java

public static GeoInformation getGeoInformation(String str) {
    GeoInformation result = null;//from ww w .  j  av a  2 s . co  m

    try {
        InetAddress adress = InetAddress.getByName(str);
        byte[] bytes = adress.getAddress();
        ArrayUtils.reverse(bytes);

        BigInteger bigInt = new BigInteger(1, adress.getAddress());

        long longAdress = bigInt.longValue();

        result = getGeoInformation(longAdress);

    } catch (UnknownHostException e) {
        logger.error("IP Adress not known: " + str);
    }

    return result;
}

From source file:com.nearinfinity.honeycomb.hbase.bulkload.FieldParser.java

/**
 * Try to parse a string into a byte string based on a column type.
 *
 * @param val    String value//from ww w  .  ja  va 2s  .  c  o m
 * @param schema Column schema to base value parsing on.
 * @return Byte string
 * @throws ParseException The string value could not be parsed into the column type.
 */
public static ByteBuffer parse(String val, ColumnSchema schema) throws ParseException {
    checkNotNull(val, "Should not be parsing null. Something went terribly wrong.");
    checkNotNull(schema, "Column metadata is null.");

    ColumnType type = schema.getType();

    if (val.length() == 0 && type != ColumnType.STRING && type != ColumnType.BINARY) {
        if (schema.getIsNullable()) {
            return null;
        }

        throw new IllegalArgumentException(
                "Expected a value for a" + " non-null SQL column, but no value was given.");
    }

    switch (type) {
    case LONG:
        return ByteBuffer.wrap(Longs.toByteArray(Long.parseLong(val)));
    case ULONG:
        BigInteger n = new BigInteger(val);
        if (n.compareTo(BigInteger.ZERO) == -1) {
            throw new IllegalArgumentException("negative value provided for unsigned column. value: " + val);
        }
        return ByteBuffer.wrap(Longs.toByteArray(n.longValue()));
    case DOUBLE:
        return ByteBuffer.wrap(Bytes.toBytes(Double.parseDouble(val)));
    case DATE:
        return extractDate(val, "yyyy-MM-dd", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy.MM.dd", "yyyyMMdd");
    case TIME:
        return extractDate(val, "HH:mm:ss", "HH:mm:ss", "HHmmss");
    case DATETIME:
        return extractDate(val, "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss",
                "yyyy.MM.dd HH:mm:ss", "yyyyMMdd HHmmss");
    case DECIMAL:
        return extractDecimal(val, schema.getPrecision(), schema.getScale());
    case STRING:
    case BINARY:
    default:
        return ByteBuffer.wrap(val.getBytes(Charset.forName("UTF-8")));
    }
}

From source file:main.java.utils.Utility.java

public static long sha512Hash(String key) {
    String value = DigestUtils.sha512Hex(key.getBytes());
    BigInteger b = new BigInteger(value, 16);

    return (b.longValue());
}

From source file:ac.elements.parser.SimpleDBConverter.java

/**
 * Decodes zero-padded positive long value from the string representation
 * //from ww w.java2  s .com
 * com.xerox.amazonws.sdb.DataUtils
 * 
 * @param value
 *            zero-padded string representation of the long
 * @return original long value
 */
private static long decodeLong(String value) {
    BigInteger bi = new BigInteger(value, RADIX);
    bi = bi.add(BigInteger.valueOf(Long.MIN_VALUE));
    return bi.longValue();
}