public static int[] toOperation(int x,int num,int top) {
int[] arr1 = new int[32]; //定义int型数组
int key,pos = arr1.length - 1; //定义变量
for ( ;pos >= 0;pos--) { //定义循环
key = x & num; //进行位运算将有效位保留
arr1[pos] = key; //将有效数值传人自定义数组
x = x >> top; //通过位作除法运算
}
/*
for ( ;pos >= 0;pos-- ) {
key = x % (num + 1);
arr1[pos] = key;
x = x / (num + 1);
}
*/
return arr1; //将运算结果返回
}
//二进制Binary
public static void Binary(int x) { //定义二进制转换方法
int num = 1;
int top = 1;
System.out.print("二进制:");
arrary(toOperation(x,num,top)); //调用运算及输出方法
}
//八进制Octa
public static void Octa(int x) { //定义八进制转换方法
int num = 7;
int top = 3;
System.out.print("八进制:");
arrary(toOperation(x,num,top)); //调用运算及输出方法
}
//十六进制Hex
public static void Hex(int x) { //定义十六进制转换方法
int num = 15;
int top = 4;
System.out.print("十六进制:");
arrary(toOperation(x,num,top)); //调用运算及输出方法
}