@Test public void testEncodePositiveInteger() { assertEquals("15pn7", encodeBase32(1234567, 5)); }
public static String encodeBase32(long i, int length) { char[] buf = new char[65]; int charPos = 64; boolean negative = (i < 0); if (!negative) i = -i; while (i <= -32) { buf[charPos--] = characters[(int) (-(i % 32))]; i /= 32; } buf[charPos] = characters[(int) (-i)]; String result = padLeftWithZerosToLength(new String(buf, charPos, (65 - charPos)), length); if (negative) return "-" + result; else return result; }
Base32 { public static String encodeBase32(long i, int length) { char[] buf = new char[65]; int charPos = 64; boolean negative = (i < 0); if (!negative) i = -i; while (i <= -32) { buf[charPos--] = characters[(int) (-(i % 32))]; i /= 32; } buf[charPos] = characters[(int) (-i)]; String result = padLeftWithZerosToLength(new String(buf, charPos, (65 - charPos)), length); if (negative) return "-" + result; else return result; } }
Base32 { public static String encodeBase32(long i, int length) { char[] buf = new char[65]; int charPos = 64; boolean negative = (i < 0); if (!negative) i = -i; while (i <= -32) { buf[charPos--] = characters[(int) (-(i % 32))]; i /= 32; } buf[charPos] = characters[(int) (-i)]; String result = padLeftWithZerosToLength(new String(buf, charPos, (65 - charPos)), length); if (negative) return "-" + result; else return result; } private  Base32(); }
Base32 { public static String encodeBase32(long i, int length) { char[] buf = new char[65]; int charPos = 64; boolean negative = (i < 0); if (!negative) i = -i; while (i <= -32) { buf[charPos--] = characters[(int) (-(i % 32))]; i /= 32; } buf[charPos] = characters[(int) (-i)]; String result = padLeftWithZerosToLength(new String(buf, charPos, (65 - charPos)), length); if (negative) return "-" + result; else return result; } private  Base32(); static String encodeBase32(long i, int length); static String encodeBase32(long i); static long decodeBase32(String hash); }
Base32 { public static String encodeBase32(long i, int length) { char[] buf = new char[65]; int charPos = 64; boolean negative = (i < 0); if (!negative) i = -i; while (i <= -32) { buf[charPos--] = characters[(int) (-(i % 32))]; i /= 32; } buf[charPos] = characters[(int) (-i)]; String result = padLeftWithZerosToLength(new String(buf, charPos, (65 - charPos)), length); if (negative) return "-" + result; else return result; } private  Base32(); static String encodeBase32(long i, int length); static String encodeBase32(long i); static long decodeBase32(String hash);  }