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
查表法
將所有元素臨時存起來,建立對應關系,每一次將&15后的值作為索引去查表,就可找到對應的元素。
char[] chs = {'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};