Java 将数字转为16进制,然后转为字符串类型


public class ArrayTest3 {
	public static void main(String[] args){
		System.out.println(toHex(60));
	}
	
    //将十进制转为16进制 public static String toHex(int num){ char[] chs = new char[8];//定义容器,存储的是字符,长度为8.一个整数最多8个16进制数 int index = chs.length-1; for(int i = 0;i<8;i++) { int temp = num & 15; if(temp > 9){ chs[index] = ((char)(temp-10+'A')); }else { chs[index] = ((char)(temp+'0')); } index--; num = num >>> 4; } return toString(chs); } //将数组转为字符串 public static String toString(char[] arr){ String temp = ""; for(int i = 0;i<arr.length;i++){ temp = temp + arr[i]; } return temp; } }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM