Ctrl K

Hexadecimal Notation

Easy
You are given a 32-bit integer value. Return a string with its hexadecimal (base-16) notation. - Digits 10 through 15 are written as lowercase letters a–f. - There must be no leading zeros; the number 0 itself is written as "0". - A negative number is written in two's complement: all 32 bits of its representation are used, which amounts to the number value + 2³². Try to do it without built-in functions that convert a whole number to hex for you.
Example 1
value=255 → 'ff'

255 = 15 · 16 + 15, so both hex digits are f.

Example 2
value=4096 → '1000'

4096 = 16³, which is a one followed by three zeros.

Example 3
value=-2 → 'fffffffe'

In 32-bit two's complement, −2 is 2³² − 2 = 0xfffffffe.

Constraints
  • −2³¹ ≤ value ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyOnly Twos Multiplied EasyThe Lost Ticket EasyOnly Fours Multiplied EasyA Prime Number of Ones Easy
loading Python…
Input
value=255
Expected
'ff'

Run checks the first 3 tests in your browser. Submit checks all 55 tests on the server, hidden ones included.