dsa · easy
Convert a Number to Hexadecimal
Convert num to hexadecimal and return the digits as a lowercase string using 0-9 and a-f. Do not prefix 0x. Strip extra leading zeros (0 itself is "0").
Arguments
num— signed 32-bit integer to write as lowercase hex
Treat num as a **32-bit two’s-complement** word: negatives use the 32-bit wrap, so -1 is thirty-two 1-bits → "ffffffff".
Example
num = 26. 26 = 1*16 + 10, and 10 is a → "1a".
num = -1 is all 32 bits set → "ffffffff".
Constraints
-2^31 <= num <= 2^31 - 1
Examples
Example 1
Input: 26 Expected: 1a
Example 2
Input: -1 Expected: ffffffff