Java examples for java.lang:long
long number to Base 36
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { long number = 2; System.out.println(toBase36(number)); }//from w w w . j a v a 2 s . c o m private static String alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static String toBase36(long number) { return toBase(number, 36); } private static String toBase(long number, int base) { if (number < base) { return Character.toString(alphabet.charAt((int) number)); } long value = number; StringBuffer sb = new StringBuffer(); while (value != 0) { int remind = (int) (value % base); value = (value - remind) / base; sb.append(alphabet.charAt(remind)); } return sb.toString(); } }