405. 数字转换为十六进制数
需要对计算机 补码有理解
class Solution {
public:
string toHex(int num) {
string hashMap = "0123456789abcdef";
unsigned int unSigNum = num;
string ans = "";
while(unSigNum != 0)
{
int temp = unSigNum &0xf;
ans = hashMap[temp] + ans;
unSigNum >>= 4;
}
return ans.size() == 0 ? "0": ans;
}
};