https www geeksforgeeks orgconvertipaddresstointegerandviceversa convert an ipv4 address to its decimal representation args ipaddress a string representing an ipv4 address e g 192 168 0 1 returns int the decimal representation of the ip address ipv4todecimal192 168 0 1 3232235521 ipv4todecimal10 0 0 255 167772415 ipv4todecimal10 0 255 traceback most recent call last valueerror invalid ipv4 address format ipv4todecimal10 0 0 256 traceback most recent call last valueerror invalid ipv4 octet 256 altipv4todecimal192 168 0 1 3232235521 altipv4todecimal10 0 0 255 167772415 convert a decimal representation of an ip address to its ipv4 format args decimalipv4 an integer representing the decimal ip address returns the ipv4 representation of the decimal ip address decimaltoipv43232235521 192 168 0 1 decimaltoipv4167772415 10 0 0 255 decimaltoipv41 traceback most recent call last valueerror invalid decimal ipv4 address https www geeksforgeeks org convert ip address to integer and vice versa convert an ipv4 address to its decimal representation args ip_address a string representing an ipv4 address e g 192 168 0 1 returns int the decimal representation of the ip address ipv4_to_decimal 192 168 0 1 3232235521 ipv4_to_decimal 10 0 0 255 167772415 ipv4_to_decimal 10 0 255 traceback most recent call last valueerror invalid ipv4 address format ipv4_to_decimal 10 0 0 256 traceback most recent call last valueerror invalid ipv4 octet 256 noqa em102 alt_ipv4_to_decimal 192 168 0 1 3232235521 alt_ipv4_to_decimal 10 0 0 255 167772415 convert a decimal representation of an ip address to its ipv4 format args decimal_ipv4 an integer representing the decimal ip address returns the ipv4 representation of the decimal ip address decimal_to_ipv4 3232235521 192 168 0 1 decimal_to_ipv4 167772415 10 0 0 255 decimal_to_ipv4 1 traceback most recent call last valueerror invalid decimal ipv4 address
def ipv4_to_decimal(ipv4_address: str) -> int:
    

    octets = [int(octet) for octet in ipv4_address.split(".")]
    if len(octets) != 4:
        raise ValueError("Invalid IPv4 address format")

    decimal_ipv4 = 0
    for octet in octets:
        if not 0 <= octet <= 255:
            raise ValueError(f"Invalid IPv4 octet {octet}")  
        decimal_ipv4 = (decimal_ipv4 << 8) + int(octet)

    return decimal_ipv4


def alt_ipv4_to_decimal(ipv4_address: str) -> int:
    
    return int("0x" + "".join(f"{int(i):02x}" for i in ipv4_address.split(".")), 16)


def decimal_to_ipv4(decimal_ipv4: int) -> str:
    

    if not (0 <= decimal_ipv4 <= 4294967295):
        raise ValueError("Invalid decimal IPv4 address")

    ip_parts = []
    for _ in range(4):
        ip_parts.append(str(decimal_ipv4 & 255))
        decimal_ipv4 >>= 8

    return ".".join(reversed(ip_parts))


if __name__ == "__main__":
    import doctest

    doctest.testmod()