@Test public void testEncodeToString() { assertEquals("", Base32.encodeToString(new byte[] {})); assertEquals("0410====", Base32.encodeToString(new byte[] {1, 2})); assertEquals("891K8HA6", Base32.encodeToString(new byte[] {0x42, 0x43, 0x44, 0x45, 0x46})); assertEquals("VS0FU07V03VG0===", Base32.encodeToString(new byte[] {-1, 0, -1, 0, -1, 0, -1, 0})); }
public static String encodeToString(byte[] bytes) { int paddingCount = (int) (8 - (bytes.length % 5) * 1.6) % 8; byte[] padded = new byte[bytes.length + paddingCount]; System.arraycopy(bytes, 0, padded, 0, bytes.length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i += 5) { long j = ((long) (padded[i] & 0xff) << 32) + ((long) (padded[i + 1] & 0xff) << 24) + ((padded[i + 2] & 0xff) << 16) + ((padded[i + 3] & 0xff) << 8) + (padded[i + 4] & 0xff); sb.append(ALPHABET.charAt((int) ((j >> 35) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 30) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 25) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 20) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 15) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 10) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 5) & 0x1f))).append(ALPHABET.charAt((int) (j & 0x1f))); } return sb.substring(0, sb.length() - paddingCount) + PADDING.substring(0, paddingCount); }
Base32 { public static String encodeToString(byte[] bytes) { int paddingCount = (int) (8 - (bytes.length % 5) * 1.6) % 8; byte[] padded = new byte[bytes.length + paddingCount]; System.arraycopy(bytes, 0, padded, 0, bytes.length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i += 5) { long j = ((long) (padded[i] & 0xff) << 32) + ((long) (padded[i + 1] & 0xff) << 24) + ((padded[i + 2] & 0xff) << 16) + ((padded[i + 3] & 0xff) << 8) + (padded[i + 4] & 0xff); sb.append(ALPHABET.charAt((int) ((j >> 35) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 30) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 25) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 20) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 15) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 10) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 5) & 0x1f))).append(ALPHABET.charAt((int) (j & 0x1f))); } return sb.substring(0, sb.length() - paddingCount) + PADDING.substring(0, paddingCount); } }
Base32 { public static String encodeToString(byte[] bytes) { int paddingCount = (int) (8 - (bytes.length % 5) * 1.6) % 8; byte[] padded = new byte[bytes.length + paddingCount]; System.arraycopy(bytes, 0, padded, 0, bytes.length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i += 5) { long j = ((long) (padded[i] & 0xff) << 32) + ((long) (padded[i + 1] & 0xff) << 24) + ((padded[i + 2] & 0xff) << 16) + ((padded[i + 3] & 0xff) << 8) + (padded[i + 4] & 0xff); sb.append(ALPHABET.charAt((int) ((j >> 35) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 30) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 25) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 20) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 15) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 10) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 5) & 0x1f))).append(ALPHABET.charAt((int) (j & 0x1f))); } return sb.substring(0, sb.length() - paddingCount) + PADDING.substring(0, paddingCount); } private  Base32(); }
Base32 { public static String encodeToString(byte[] bytes) { int paddingCount = (int) (8 - (bytes.length % 5) * 1.6) % 8; byte[] padded = new byte[bytes.length + paddingCount]; System.arraycopy(bytes, 0, padded, 0, bytes.length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i += 5) { long j = ((long) (padded[i] & 0xff) << 32) + ((long) (padded[i + 1] & 0xff) << 24) + ((padded[i + 2] & 0xff) << 16) + ((padded[i + 3] & 0xff) << 8) + (padded[i + 4] & 0xff); sb.append(ALPHABET.charAt((int) ((j >> 35) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 30) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 25) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 20) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 15) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 10) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 5) & 0x1f))).append(ALPHABET.charAt((int) (j & 0x1f))); } return sb.substring(0, sb.length() - paddingCount) + PADDING.substring(0, paddingCount); } private  Base32(); static String encodeToString(byte[] bytes); }
Base32 { public static String encodeToString(byte[] bytes) { int paddingCount = (int) (8 - (bytes.length % 5) * 1.6) % 8; byte[] padded = new byte[bytes.length + paddingCount]; System.arraycopy(bytes, 0, padded, 0, bytes.length); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i += 5) { long j = ((long) (padded[i] & 0xff) << 32) + ((long) (padded[i + 1] & 0xff) << 24) + ((padded[i + 2] & 0xff) << 16) + ((padded[i + 3] & 0xff) << 8) + (padded[i + 4] & 0xff); sb.append(ALPHABET.charAt((int) ((j >> 35) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 30) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 25) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 20) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 15) & 0x1f))).append(ALPHABET.charAt((int) ((j >> 10) & 0x1f))) .append(ALPHABET.charAt((int) ((j >> 5) & 0x1f))).append(ALPHABET.charAt((int) (j & 0x1f))); } return sb.substring(0, sb.length() - paddingCount) + PADDING.substring(0, paddingCount); } private  Base32(); static String encodeToString(byte[] bytes);  }