Convert Hexadecimal to Dotted IPv4
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure here is just a string you slice into four pieces, and Microsoft reported this one in September 2026. Convert eight hex digits into a dotted IPv4 address. Sounds trivial, and it is, until the edge cases bite. Optional 0x prefix, mixed case, wrong length, bad characters. If you've got an OA invite, this is a validation problem wearing a conversion costume. Get the checks right and the rest is four parseInt calls. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you shouldn't need it for this one.
The problem
Convert a 32-bit IPv4 address written as exactly eight hexadecimal digits into dotted-decimal notation. An optional leading 0x or 0X is allowed and hex letters are case-insensitive. Interpret the first byte as the first decimal octet. Return INVALID for any other length or character. Function hexToIpv4(value: String) → String Examples Example 1 value = "C0A80101" return = "192.168.1.1" The four bytes C0, A8, 01, and 01 become the four octets. Example 2 value = "0x7F000001" return = "127.0.0.1" The optional prefix is removed before byte conversion. Example 3 value = "ABC" return = "INVALID" The payload must contain exactly eight hexadecimal digits. Constraints 0 <= value.length <= 20. The result must use ordinary decimal octets without leading zeros.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is order of operations. Strip an optional 0x or 0X prefix first. Then check the remaining payload is exactly eight characters and every one is in 0-9, a-f, or A-F. Only after that do you slice into four 2-character chunks, parse each as base 16, and join with dots. Decimal output means no leading zeros, so 01 becomes 1, which parsing handles for free. The common pitfall is using a lenient parser that accepts signs, spaces, or partial input, so validate manually instead of trusting it. Another trap is stripping the prefix from a string like 0x alone, leaving an empty payload that must return INVALID. Also watch for a value like 0xC0A8010 with only seven digits. Constraints cap length at 20, so there's no performance concern. If you freeze on the validation order during the live OA, StealthCoder can surface a clean solution without the proctor seeing anything.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Convert Hexadecimal to Dotted IPv4 cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Convert Hexadecimal to Dotted IPv4 FAQ
How hard is the Microsoft hex to IPv4 question really?+
Easy on algorithm, annoying on edge cases. There's no clever data structure or complexity concern. The points are lost on validation: prefix handling, exact length of eight, and rejecting non-hex characters. Write the checks first and the conversion takes two minutes.
What's the trick to this problem?+
Validate before converting. Strip an optional 0x or 0X, confirm exactly eight characters remain, and confirm each is a hex digit. Then split into four byte pairs, parse each in base 16, and join with periods. Don't rely on a parser to reject bad input.
Do I need to worry about leading zeros in the output?+
Not if you convert each byte to an integer and then print it as a number. The byte 01 becomes 1 and 00 becomes 0. Leading zeros only appear if you slice the hex text and paste it through, which is the mistake to avoid.
Which edge cases should I test before submitting?+
Test an empty string, just 0x, seven and nine digit payloads, a G or other non-hex letter, lowercase input, and an uppercase 0X prefix. Also test 00000000 and FFFFFFFF for the boundary octets. Those cover nearly every failure path.
How do I prepare for this in 48 hours?+
Practice small string parsing tasks with strict validation. Write a function that checks hex characters by hand, then slices and converts. Spend the rest of the time on similar format conversion problems, since this reported September 2026 question is more about care than cleverness.