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