Here you can find the source of encodeToString(final BigInteger input)
Parameter | Description |
---|---|
input | a parameter |
private static String encodeToString(final BigInteger input)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { private static final String ENCODE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"; /**// w w w . j ava 2 s . co m * Represent bytes (from a hash) as a nice printable string * * @param mdbytes * @return */ public static String encodeToString(final byte[] mdbytes) { return encodeToString(new BigInteger(1, mdbytes)); } /** * Big integer to much smaller string encoding * * @param input * @return */ private static String encodeToString(final BigInteger input) { final BigInteger encodeLength = BigInteger.valueOf(ENCODE.length()); BigInteger running = input; BigInteger mod; final StringBuilder result = new StringBuilder(64); result.append(running.intValue() == 0 ? "0" : ""); while (running.longValue() != 0) { mod = running.remainder(encodeLength); result.append(ENCODE.substring(mod.intValue(), mod.intValue() + 1)); running = running.divide(encodeLength); } return result.reverse().toString(); } }