java进制转换

/*
    用于进制转换的函数
    */
    private 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 & base;
            arr[--pos] = chs[temp];
            num = num >>> offset;
        }
        for(int x = pos; x<arr.length; x++){
            System.out.println(arr[x]);

        }
        System.out.println();
    }

 

posted @ 2015-07-08 19:59  虞秀权  阅读(368)  评论(0编辑  收藏  举报