https://leetcode.com/problems/convert-a-number-to-hexadecimal/
求一个数的十六进制补码表示
几个问题:1、能用位运算就用为预算,比如求16的余数,不要用区余操作,用&15;2、>>>是无符号右移操作,适用于部分负数的移位运算
public class Solution {
public String toHex(int num) {
char[] dict = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
StringBuilder sb = new StringBuilder();
do {
sb.append(dict[num & 15]);
num = num >>> 4;
} while (num != 0);
return sb.reverse().toString();
}
}