2016年6月18日 星期六

//模擬十進位轉換十六進位

//模擬十進位轉換十六進位

public class Decimal2Hex
{
public static void main(String[] args)
{
//十六進位符號轉換表,以陣列表示
char hex[] = {'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F'}; 

byte decA = 123; 
int hiA = (decA & 0b1111_0000) >> 4; //取得高4位元的十六進位值
int loA = (decA & 15); //取得低4位元的十六進位值

System.out.println("decA = 0x" + hex[hiA] + hex[loA]); 
}
}




沒有留言:

張貼留言