class Solution {
public:
string toHex(int num) {
const string HEX ="0123456789abcdef";
if (num==0) return "0";
string res ="";
int count = 0;
while (num&&count++<8) {
//&0xf表示取二进制的低四位
res = HEX[(num&0xf)]+res;
num>>=4;
}
return res;
}
};
Convert a Number to Hexadecimal
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.