码迷,mamicode.com
首页 > 其他好文 > 详细

进制转换

时间:2017-10-18 22:11:41      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:oid   images   code   ati   进制转换   span   es2017   alt   hex   

public static void toHex(int num,int base,int offset){
    if(num==0){
        System.out.print("0");  
     return;
}
char[] chs={‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘, ‘7‘,‘8‘,‘9‘,‘A‘,‘B‘,‘C‘, ‘D‘,‘E‘,‘F‘}; char[] arr = new char[8]; int pos = arr.length; while(num!=0){ int temp = num & base; arr[--pos] = chs[temp]; num = num >>> offset; } for(int i=pos;i<arr.length;i++){ System.out.print(arr[i]); } }

使用位运算,不断取二进制的后4位。技术分享

 

进制转换

标签:oid   images   code   ati   进制转换   span   es2017   alt   hex   

原文地址:http://www.cnblogs.com/guoyunhao/p/7689262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!