Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-263

Integer to IPv4 Address

Problem

Convert a 32-bit unsigned integer to its dotted IPv4 address string.

Extract four octets from the least significant end using division by 256, then join them from most to least significant. Assume the value is between 0 and 2 to the 32 minus 1.

Hint

Taking value modulo 256 peels off the least significant octet.

Test cases

case 1
in: [0]
expected: "0.0.0.0"
case 2
in: [4294967295]
expected: "255.255.255.255"
case 3
in: [3232235777]
expected: "192.168.1.1"
case 4
in: [1]
expected: "0.0.0.1"
case 5
in: [16909060]
expected: "1.2.3.4"
Starter codePython
def int_to_ip(value):
    # Your code here
    pass

5 test cases · run your code against them in the editor