# Problem Statement
Write a function that takes two string parameters, an IP (v4) address and a subnet mask, and returns two strings: the network block, and the host identifier.

The function does not need to support CIDR notation.

# Description
A single IP address with subnet mask actually specifies several addresses: a network block, and a host identifier, and a broadcast address. These addresses can be calculated using a bitwise AND operation on each bit.

(The broadcast address is not used in this kata.)

## Example
A computer on a simple home network might have the following IP and subnet mask:
```
IP: 192.168.2.1
Subnet: 255.255.255.0
(CIDR Notation: 192.168.2.1 /24)
```
In this example, the network block is: **192.168.2.0**. And the host identifier is: **0.0.0.1**. 

## bitwise AND 
To calculate the network block and host identifier the bits in each octet are ANDed together. When the result of the AND operation is '1', the bit specifies a network address (instead of a host address).

To compare the first octet in our example above, convert both the numbers to binary and perform an AND operation on each bit:
```
11000000 (192 in binary)
11111111 (255 in binary)
--------------------------- (AND each bit)
11000000 (192 in binary)
```
So in the first octet, '**192**' is part of the network address. The host identifier is simply '**0**'.

For more information see the [Subnetwork](http://en.wikipedia.org/wiki/Subnetwork) article on Wikipedia.

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Mathematics

Starter code: def ipv4__parser(ip_addr, mask):
	

Solutions:
def ipv4__parser(addr, mask):
	return tuple(('.'.join((str(n) for n in a)) for a in zip(*((a & m, a & ~m) for (a, m) in zip((int(n) for n in addr.split('.')), (int(n) for n in mask.split('.')))))))


from socket import inet_aton, inet_ntoa
from struct import Struct
Addr = Struct('>I')

def ipv4__parser(ip_addr, mask):
	(i,) = Addr.unpack(inet_aton(ip_addr))
	(m,) = Addr.unpack(inet_aton(mask))
	return (inet_ntoa(Addr.pack(i & m)), inet_ntoa(Addr.pack(i & ~m)))


from socket import inet_aton, inet_ntoa
from struct import unpack, pack
to_int = lambda s: unpack('>L', inet_aton(s))[0]
to_ip = lambda x: inet_ntoa(pack('>L', x))

def ipv4__parser(ip_addr, mask):
	(ip, m) = (to_int(ip_addr), to_int(mask))
	return (to_ip(ip & m), to_ip(ip & ~m))


def ipv4__parser(ip_addr, mask):
	arr = [(int(p), int(m)) for (p, m) in zip(ip_addr.split('.'), mask.split('.'))]
	return ('.'.join((str(a & b) for (a, b) in arr)), '.'.join((str(a & b ^ a) for (a, b) in arr)))


def ipv4__parser(ip_addr, mask):
	net_addr = '.'.join((str(int(a) & int(b)) for (a, b) in zip(ip_addr.split('.'), mask.split('.'))))
	host_addr = '.'.join((str(int(a) & 255 - int(b)) for (a, b) in zip(ip_addr.split('.'), mask.split('.'))))
	return (net_addr, host_addr)


def ipv4__parser(ip_addr, mask):
	host = []
	network = []
	ip_addr = [int(s) for s in ip_addr.split('.')]
	mask = [int(s) for s in mask.split('.')]
	for octet in range(4):
		host += [ip_addr[octet] & mask[octet]]
		network += [ip_addr[octet] & ~mask[octet]]
	host = [str(i) for i in host]
	network = [str(i) for i in network]
	return ('.'.join(host), '.'.join(network))


def ipv4__parser(ip, m):
	(n, h) = ('', '')
	for (i, j) in zip(ip.split('.'), m.split('.')):
		r = int(''.join([str(int(k) & int(l)) for (k, l) in zip(bin(int(i))[2:].zfill(8), bin(int(j))[2:].zfill(8))]), 2)
		n += str(r) + '.'
		h += str(int(i) - r) + '.'
	return (n.strip('.'), h.strip('.'))


def ipv4__parser(ip_addr, mask):
	(ip, sMask) = (ip_addr.split('.'), mask.split('.'))
	nb = [str(int(a) & int(b)) for (a, b) in zip(ip, sMask)]
	hi = [str(int(a) - int(b)) for (a, b) in zip(ip, nb)]
	return ('.'.join(nb), '.'.join(hi))


def ipv4__parser(ip_addr, mask):
	net_addr = '.'.join([str(int(i) & int(m)) for (i, m) in zip(ip_addr.split('.'), mask.split('.'))])
	host_addr = '.'.join([str(int(i) - int(n)) for (i, n) in zip(ip_addr.split('.'), net_addr.split('.'))])
	return (net_addr, host_addr)


def to_int(n):
	return sum((int(i) * 256 ** e for (e, i) in enumerate(reversed(n.split('.')))))

def to_ip(n):
	return '.'.join((str(n // 256 ** e & 255) for e in range(3, -1, -1)))

def ipv4__parser(ip_addr, mask):
	addr = to_int(ip_addr)
	mask = to_int(mask)
	return (to_ip(addr & mask), to_ip(addr & ~mask))