- class ArrayTest7
- {
- public static void main(String[] args)
- {
- toHex_1(60);
- toHex_1(-60);
- }
- //查表法:十进制-->十六进制。
- public static void toHex_1(int num)
- {
- //先制表
- char[] chs = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
- char[] arr = new char[8];
- int pos = arr.length-1;
- if(num == 0)
- {
- System.out.println("0" );
- return;
- }
- while(num!=0)
- {
- arr[pos--]=chs[num&15];
- num = num>>>4;
- }
- for(int x=pos+1;x<arr.length;x++)
- {
- System.out.print(arr[x]);
- }
- }
- }
复制代码
|
|