- class jinz
- {
- public static void main(String[] args)
- {
- int a=16;
- hex(a);
- }
- public static void hex(int num)
- {
- trans(num,15,4);
- }
- public static void trans(int num,int base,int offet)
- {
- char cha[]={'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 c=num&base;
- arr[--pos]=cha[c];
- num=num>>>offet;
- }
- for(int x=pos;x<arr.length;x++)
- {System.out.println(arr[pos]);}
- }
复制代码 |
|