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);  }
@Test public void testEncodePositiveInteger() { assertEquals("15pn7", encodeBase32(1234567, 5)); }
@Test public void testEncodesZero() { assertEquals("0", encodeBase32(0, 1)); }
@Test public void testEncodesNegativeInteger() { assertEquals("-3v", encodeBase32(-123, 2)); }
@Test public void testEncodePadsToLength12() { assertEquals("00000000003v", encodeBase32(123)); }