Take the following IPv4 address:  128.32.10.1
This address has 4 octets where each octet is a single byte (or 8 bits).

* 1st octet 128 has the binary representation: 10000000
* 2nd octet 32 has the binary representation: 00100000
* 3rd octet 10 has the binary representation: 00001010
* 4th octet 1 has the binary representation: 00000001

So 128.32.10.1 == 10000000.00100000.00001010.00000001

Because the above IP address has 32 bits, we can represent it as the 32
bit number: 2149583361.

Write a function ip_to_int32(ip) ( **JS**: `ipToInt32(ip)` ) that takes an IPv4 address and returns
a 32 bit number.

```python
  ip_to_int32("128.32.10.1") => 2149583361
```

Difficulty: introductory

Starter code:

def ip_to_int32(ip):
	

Solutions:
def ip_to_int32(ip):
    """
    Take the following IPv4 address: 128.32.10.1 This address has 4 octets
    where each octet is a single byte (or 8 bits).

    1st octet 128 has the binary representation: 10000000
    2nd octet 32 has the binary representation: 00100000
    3rd octet 10 has the binary representation: 00001010
    4th octet 1 has the binary representation: 00000001
    So 128.32.10.1 == 10000000.00100000.00001010.00000001

    Because the above IP address has 32 bits, we can represent it as
    the 32 bit number: 2149583361.

    Write a function ip_to_int32(ip) ( JS: ipToInt32(ip) ) that takes
    an IPv4 address and returns a 32 bit number.

    ip_to_int32("128.32.10.1") => 2149583361

    """
    addr = ip.split(".")
    res = int(addr[0]) << 24
    res += int(addr[1]) << 16
    res += int(addr[2]) << 8
    res += int(addr[3])
    return res


def ip_to_int32(ip):
    return reduce(lambda acc, x: acc << 8 | x, (int(x) for x in ip.split('.')))

def ip_to_int32(ip):
    r =""
    for i in ip.split('.'):
        r += "{0:08b}".format(int(i))
    return int(r, 2)

def ip_to_int32(ip):
  return int(''.join([(bin(int(x))[2:]).zfill(8) for x in ip.split('.')]),2)

def ip_to_int32(ip):
    return reduce(lambda p, n: (p << 8) + int(n), ip.split('.'), 0)

def ip_to_int32(ip):
    return sum(int(o) << (8*i) for i, o in enumerate(ip.split(".")[::-1]))

def ip_to_int32(ip):
  retInt = 0
  octets = ip.split('.')
  for ndx, offset in enumerate((24, 16, 8, 0)):
      retInt = retInt | int(octets[ndx]) << offset
  return retInt

import struct
from socket import inet_aton

def ip_to_int32(ip):
    return struct.unpack('>I', inet_aton(ip))[0]

def ip_to_int32(ip):
    result = 0
    for s in ip.split('.'):
        result *= 256
        result += int(s)
    return result

def ip_to_int32(ip):
    return int(''.join([(format(int(i),"08b")) for i in ip.split('.')]),2)