405.Convert A Number to Hexadecimal
示例 1:
输入:
26
输出:
"1a"
示例 2:
输入:
-1
输出:
"ffffffff"Last updated
示例 1:
输入:
26
输出:
"1a"
示例 2:
输入:
-1
输出:
"ffffffff"Last updated
class Solution {
char u16[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
int temp=15;
public:
string toHex(int num) {
if(num==0) return "0";
unsigned int N=num;
string res;
while(N)
{
//cout<<num<<endl;
int index=(N & temp);
res=u16[index]+res;
N>>=4;
}
return res;
}
};