Convert a Hexadecimal Address to Dotted IPv4
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Convert an eight-digit hexadecimal address to network-order dotted IPv4 with strict validation, optional prefixes, and correct high-bit handling.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- Input is a string of length at most 100.
- Accept exactly eight ASCII hexadecimal digits, optionally preceded by 0x or 0X; digits are case-insensitive.
- Whitespace, signs, separators and any other length or character return INVALID.
- Use network-order bytes, including unsigned 32-bit patterns with the high bit set.
- Valid output has four decimal octets separated by dots, without leading zeroes.
Examples
Input: ('C0A80101',)
Expected Output: '192.168.1.1'
Explanation: Network order keeps the leftmost byte first.
Input: ('0xffffffff',)
Expected Output: '255.255.255.255'
Explanation: An unsigned high-bit value is valid.