Leetcode Problem 405. Convert a Number to Hexadecimal
405. Convert a Number to Hexadecimal
Leetcode Solutions
Bitwise Manipulation and Hexadecimal Conversion
Create a map of hexadecimal characters for values 0 to 15.
Check if the input number is 0, and return '0' if true.
Initialize an empty string to store the result.
Use a loop to process the number until it becomes 0:
a. Use bitwise AND with 15 (0xF) to get the last 4 bits of the number.
b. Use the map to find the corresponding hexadecimal character and prepend it to the result string.
c. Right shift the number by 4 bits to process the next group.