Convert a Number to Hexadecimal
Input:
26
Output:
"1a"Input:
-1
Output:
"ffffffff"Last updated
Input:
26
Output:
"1a"Input:
-1
Output:
"ffffffff"Last updated
class Solution:
def toHex(self, num: int) -> str:
if num == 0:
return'0'
elif num < 0:
num += 2**32
mp = '0123456789abcdef'
res = ''
for i in range(8):
n = num & 15
res = mp[n] + res
num= num >> 4
return res.lstrip('0')