class Number
{
public static void main(String[] args)
{
System.out.println("Hello World!");
System.out.println("----------------");
//toBin(5);
//toHex(-60);
trans(5,1,1);
}
public static void trans(int num,int base,int offset)
{
char[] chs ={'0','1','2','3'
,'4','5','6','7'
,'8','9','A','B'
,'C','D','E','F'};
char[] arr =new char[32];
int pos = arr.length;
while(num!=0)
{
int temp = num & 15;
arr [--pos] = chs[temp];
num = num>>>4;
}
for (int x=pos;x<arr.length ;x++ )
{
System.out.print(arr[x]);
}
}
}
这个优化的结果十六进制的可以转化,为什么二进制的就转化不了? |
|