Decimal to Hexadecimal Conversion - aloalgo

Decimal to Hexadecimal Conversion

Medium

You are given an integer num, convert it to hexadecimal. For negative integers, the two's complement method is used.

The hexadecimal string should not contain any extra leading zeros. If the number is zero, its hexadecimal representation is "0". All letters in the hexadecimal string (a-f) should be lowercase.

You may not use any built-in library's functions that directly convert an integer to a hexadecimal string.

Example 1

Input
26
Output
"1a"
Explanation:

26 in decimal is 1a in hexadecimal.

Example 2

Input
-1
Output
"ffffffff"
Explanation:

-1 in decimal, using two's complement for a 32-bit integer, is ffffffff in hexadecimal. This represents the maximum 32-bit unsigned integer value.

Example 3

Input
0
Output
"0"
Explanation:

0 in decimal is 0 in hexadecimal.

Loading...
Input
26
Output
"1a"

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!