将一个数转换为十六进制。定义以下函- public static void toHex2(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=0;
- while (num!=0 )
- {
- int temp=num & 15;
- arr[pos++]=chs[temp];
- num=num >>> 4;
-
- }
- System.out.println("pos="+pos);
- for (int x=arr.length-1;x>=0 ;x-- )
- {
- System.out.print(arr[x]+",");
- }
- }
复制代码 返回的结果为何会有a存在.
|
|