Skip to content

Practice Convert a Number to Hexadecimal

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#405
LeetCode Problem

Convert a Number to Hexadecimal

Problem Statement

Given a 32-bit integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself. Note: You are not allowed to use any built-in library method to directly solve this problem.

Source: Convert a Number to Hexadecimal on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
num = 26
Output
"1a"

# Example 2

Input
num = -1
Output
"ffffffff"

Constraints

-2^31 <= num <= 2^31 - 1

Related LeetCode Problems

Practice more problems similar to Convert a Number to Hexadecimal.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.