版权声明:博客文章都是作者辛苦整理的,转载请注明出处,谢谢! https://cloud.tencent.com/developer/article/1433649
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
class Solution {
public:
string toHex(int num) {
if(num == 0) {
return "0";
}
string s;
const string HEXO = "0123456789abcdef";
while(num != 0 && s.length() < 8) {
s += HEXO[num & 0xf];
num >>= 4;
}
reverse(s.begin(), s.end());
return s;
}
};
class Solution {
public:
string toHex(int num) {
if(num == 0) {
return "0";
}
unsigned int n = num;
string s;
const string HEXO = "0123456789abcdef";
while(n) {
int remainder = n % 16;
s += HEXO[remainder];
n >>= 4;
}
reverse(s.begin(), s.end());
return s;
}
};