List of usage examples for java.math BigInteger BigInteger
private BigInteger(long val)
From source file:Main.java
public static int compareTimestamps(String lhsTimestamp, String rhsTimestamp) { BigInteger lhs = new BigInteger(lhsTimestamp); BigInteger rhs = new BigInteger(rhsTimestamp); return lhs.compareTo(rhs); }
From source file:Main.java
public static boolean isBetweenTimeStr(String time, String starttime, String endtime) { try {/* www . j a v a 2s . c o m*/ BigInteger timeInt = new BigInteger(time); BigInteger starttimeInt = new BigInteger(starttime); BigInteger endttimeInt = new BigInteger(endtime); int compareResult = timeInt.compareTo(starttimeInt); if (compareResult == -1) { return false; } else if (compareResult == 0) { return true; } else if (compareResult == 1) { compareResult = timeInt.compareTo(endttimeInt); if (compareResult >= 0) { return false; } else { return true; } } return false; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static BigInteger OS2IP(byte[] _os) { byte[] _osWithPadding = new byte[_os.length + 1]; System.arraycopy(_os, 0, _osWithPadding, 1, _os.length); return new BigInteger(_osWithPadding); }
From source file:Main.java
/** * Transforms a number String to a byte array * @param in number String/*from w w w. ja v a2s . c o m*/ * @return */ public static byte[] NumStringToBytes(String in) { BigInteger num = new BigInteger(in); byte[] bytes = num.toByteArray(); if (bytes.length > 0) { if (bytes[0] == 0) { byte[] cuttedByte = new byte[bytes.length - 1]; System.arraycopy(bytes, 1, cuttedByte, 0, bytes.length - 1); return cuttedByte; } } return num.toByteArray(); }
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 .j a va2 s.c om }
From source file:Main.java
public static BigInteger readBigInteger(ByteArrayInputStream bais) { return new BigInteger(readData(bais)); }
From source file:Main.java
/** * Transforms a byte array to a signed//from w w w . j a v a 2 s. c o m * number String * @param in byte array * @return signed num String */ public static String bytesToSignedNumString(byte[] in) { BigInteger num = new BigInteger(in); return num.toString(); }
From source file:Main.java
public static byte[] base58ToBytes(String value) { BigInteger bigNum58 = new BigInteger("58"); BigInteger tempBigValue = new BigInteger("0"); int leadingZeroes = 0; boolean justStarted = true; for (int i = 0; i < value.length(); i++) { if (justStarted && value.toCharArray()[i] == '1') { leadingZeroes++;/*from w ww .ja v a 2 s . c o m*/ } else { justStarted = false; tempBigValue = tempBigValue.add(bigNum58.pow(value.length() - i - 1) .multiply(new BigInteger("" + base58Array.indexOf(value.toCharArray()[i])))); } } byte[] bigValue = tempBigValue.toByteArray(); int bigValueStart = 0; for (int j = 0; j < bigValue.length; j++) { if (bigValue[j] != 0) { bigValueStart = j; break; } } byte[] byteResult = new byte[bigValue.length + leadingZeroes - bigValueStart]; for (int i = 0; i < byteResult.length; i++) { if (i - leadingZeroes + bigValueStart < bigValue.length && i - leadingZeroes + bigValueStart >= 0) byteResult[i] = i < leadingZeroes ? 0 : bigValue[i - leadingZeroes + bigValueStart]; } return byteResult; }
From source file:Main.java
/** * <p>//w w w. j av a 2 s .c om * Converts a 8 byte long byte array into a long value * </p> * * @param b * the 8 byte array containing the bits of the long value * @return the converted long object */ public static long byte2long(byte[] b) { return new BigInteger(b).longValue(); }
From source file:Main.java
public static BigInteger sumRights(String[] rights) { BigInteger num = new BigInteger("0"); for (int i = 0; i < rights.length; i++) { num = num.setBit(Integer.parseInt(rights[i])); }/* w ww.j a v a 2 s .co m*/ return num; }