- public static int toDec(String str, int radix)
- {
- char[] chs = {'0','1','2','3',
- '4','5','6','7',
- '8','9','A','B',
- 'C','D','E','F'};
- char[] num = str.toCharArray();
- int dec = 0;
-
- for (int len=num.length, i=len-1; i>=0; i--)
- {
- if (i==0 && num[0]=='-')
- {
- dec = -dec;
- }
- for (int j = 0; j<radix; j++)
- {
- if (chs[j]==num[i])
- {
- dec += j*Math.pow(radix,len-i-1);
- }
- }
- }
- return dec;
- }
复制代码 写了个方法供楼主参考 |