#2932-bit Status Code Converter
You are developing a system diagnostics tool that receives a 32-bit status value generated by a computer system. For easier debugging, the diagnostic tool must display the value in its hexadecimal representation. Given a signed 32-bit integer statusCode, return its hexadecimal representation as a lowercase string.
Rules:
- Use lowercase hexadecimal characters (0-9 and a-f).
- Do not include leading zeros.
- The value 0 must be represented as "0".
- For negative values, use the 32-bit two's-complement representation.
- You cannot use a built-in function that directly converts an integer to hexadecimal.
- The conversion must be performed using bitwise operations or equivalent arithmetic logic.
Real-World Application: System error and status logs; Hardware register inspection; Debugging and forensic analysis;
Examples
Example 1
Input: statusCode = 26
Output: "1a"
Explanation:
The decimal status value 26 corresponds to hexadecimal 1a.
Example 2
Input: statusCode = -1
Output: "ffffffff"
Explanation:
The 32-bit two's-complement representation of -1 is 0xffffffff.
Example 3
Input: statusCode = 0
Output: "0"
Explanation:
Zero has a single hexadecimal representation and should not contain leading zeros.
Constraints
- -2^31 <= statusCode <= 2^31 - 1
- statusCode is a signed 32-bit integer.
- The output contains only 0-9 and a-f.
- The output length is between 1 and 8 characters.