https://leetcode.com/problems/convert-a-number-to-hexadecimal/description/
class Solution {
public:
string toHex(int num) {
string res = "";
for(int i=0; num&&i<8; i++){
int t = num& 0xf;
if(t>=10) res = char('a'+t-10) + res;
else res = char('0'+t) + res;
num >>= 4;
}
return res.empty()?"0":res;
}
};
版权声明:本文为u013554860原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。