十進制轉十六進制

package cn.imust.day;

public class TestChange {

	public static void main(String[] args){
		toHex(60);
	}

	private static void toHex(int num) {
		// TODO Auto-generated method stub
		//decimal system transfer to hexdecimal
		
			StringBuffer sb=new StringBuffer();
			for (int x=0;x<8 ;x++ )
			{
				int temp=num&15;
				if (temp>9)
				{
					sb.append((char)(temp-10+'A'));
				}
				else 
					sb.append(temp);
				num=num>>>4;
			}
			sb=sb.reverse();
			// who know the methods to get rid of "0" before valid numbers 
			System.out.println(sb);
		}
	
}
 
The theory knowledge above is like this :

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章