本帖最后由 不想睡 于 2015-8-27 23:48 编辑
class Test_Array {
public static void main(String[] args) {
bin(60);
//oct(60);
//hex(60);
}
public static void bin(int num) {
transition(num,1,1);
}
public static void oct(int num) {
transition(num,7,3);
}
public static void hex(int num) {
transition(num,15,4);
}
public static void transition(int num ,int base ,int offset) {
char[] ch ={'0','1','2','3','4',
'5','6','7','8','9',
'A','B','C','D','E','F'};
char[] arr = new char [32];
int pointer = arr.length;
while (num != 0) {
int temp = num & base;
arr[--pointer] = ch[temp];
num = num >>> offset;
}
print(arr,pointer);
}
public static void print(char[] arr,int pointer) {
for (int x = pointer;x < arr.length;x++ ) {
System.out.print(arr[x]);
}
}
}
|
|