List of utility methods to do BigInteger Format
String | formatBigInteger(BigInteger bi, int length) format Big Integer String s = bi.toString(16); StringBuffer buf = new StringBuffer(s.length()); int zeroesToAppend = length - s.length(); int count = 0; buf.append(" "); for (int i = 0; i < zeroesToAppend; i++) { count++; buf.append('0'); ... |
void | formatBigIntegerBinary(final long value, byte[] buf, final int offset, final int length, final boolean negative) format Big Integer Binary BigInteger val = BigInteger.valueOf(value); final byte[] b = val.toByteArray(); final int len = b.length; final int off = offset + length - len; System.arraycopy(b, 0, buf, off, len); final byte fill = (byte) (negative ? 0xff : 0); for (int i = offset + 1; i < off; i++) { buf[i] = fill; ... |
String | formatSerialNumber(BigInteger bi) format Serial Number if (bi == null) { return ""; String sn = bi.toString(16); char[] chars = sn.toUpperCase().toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < chars.length; i++) { sb.append(chars[i]); ... |
String | formatSerialNumber(final BigInteger serial) Get a proper string representation of a certificate's serial number. StringBuffer b = new StringBuffer(serial.toString(16).toUpperCase()); if ((b.length() % 2) != 0) { b.insert(0, "0"); int index = 2; for (index = 2; index < b.length(); index += 3) { b.insert(index, ":"); return b.toString(); |
String | formatSize(BigInteger size) format Size if (size.compareTo(ONE_THOUSAND) == 1) { return size.divide(ONE_THOUSAND).toString() + " TB"; } else return size.toString() + " GB"; |
String | formatTime(BigInteger femto) format Time if (femto.equals(BigInteger.ZERO)) return "0"; StringBuilder time = new StringBuilder(femto.toString()); String[] units = { "fs", "ps", "ns", "us", "ms", "sec", "ksec", "Msec" }; for (String unit : units) { if (time.length() <= 3 || !time.toString().endsWith("000")) return time + " " + unit; time.setLength(time.length() - 3); ... |