| 224 | } |
| 225 | |
| 226 | public static String binaryToBase58(Object buff2) { |
| 227 | byte[] buff = (byte[]) buff2; |
| 228 | if (buff.length == 0) return ""; |
| 229 | int zeros = 0; |
| 230 | while (zeros < buff.length && buff[zeros] == 0) zeros++; |
| 231 | // prepend a 0 byte so BigInteger treats input as unsigned |
| 232 | byte[] unsigned = new byte[buff.length + 1]; |
| 233 | System.arraycopy(buff, 0, unsigned, 1, buff.length); |
| 234 | BigInteger n = new BigInteger(unsigned); |
| 235 | BigInteger base = BigInteger.valueOf(58); |
| 236 | StringBuilder sb = new StringBuilder(); |
| 237 | while (n.signum() > 0) { |
| 238 | BigInteger[] qr = n.divideAndRemainder(base); |
| 239 | sb.insert(0, B58_ALPHABET.charAt(qr[1].intValue())); |
| 240 | n = qr[0]; |
| 241 | } |
| 242 | for (int i = 0; i < zeros; i++) sb.insert(0, '1'); |
| 243 | return sb.toString(); |
| 244 | } |
| 245 | |
| 246 | public static String intToBase16(Object number) { |
| 247 | long n = Long.parseLong(String.valueOf(number)); |