Modulus vs Bit manipulation &
When converting a decimal number to hexadecimal, I always use modulus. There is another way of doing this.
- Mod operation
int digit = num % 16
- Bit operation
int digit = num & 15
查表法
將所有元素臨時存起來裕循,建立對應(yīng)關(guān)系粱锐,每一次將&15后的值作為索引去查表,就可找到對應(yīng)的元素俄删。
char[] chs = {'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};