00 0th bottles
1 1
0 2
1 3
0 4
1 5
0 6
1 7
Public class Base {/*** convert the number to any base * @ param num * @ param base * @ return */public String baseString (int num, int Base) {if (base> 16) {throw new RuntimeException ("the number of hexadecimal bytes exceeds the range, base <= 16");} StringBuffer str = new StringBuffer (""); string digths = "0123456789 ABCDEF"; Stack <Character> s = new Stack <Character> (); while (num! = 0) {s. push (digths. charAt (num % base); num/= base;} while (! S. isEmpty () {str. append (s. pop ();} return str. toString ();} /*** any hexadecimal conversion in hexadecimal format * @ param num * @ param srcBase * @ param destBase * @ return */public String baseNum (String num, int srcBase, int destBase) {if (srcBase = destBase) {return num;} String digths = "0123456789 ABCDEF"; char [] chars = num. toCharArray (); int len = chars. length; if (destBase! = 10) {// The destination system is not converted to the decimal num = baseNum (num, srcBase, 10);} else {int n = 0; for (int I = len-1; I> = 0; I --) {n + = digths. indexOf (chars [I]) * Math. pow (srcBase, len-I-1);} return n + "";} return baseString (Integer. valueOf (num), destBase );}}
Reprinted please indicate the source: http://blog.csdn.net/u012027907