#!/usr/bin/env python
# -*- coding:utf-8 -*-
ip = '192.168.0.1'
# 转为二进制:
# 方法一
'''
eve = ip.split('.')
s = ''
for i in eve:
i = int(i)
ejz = bin(i)
s += ejz+','
print(s[:-1])
'''
# 方法二
'''
eve = ip.split('.')
s = []
for i in eve:
i = int(i)
ejz = bin(i)
s.append(ejz)
print(','.join(s))
'''
# 补齐八位,拼接二进制转为十进制
# 方法一
'''
s = ''
ip_list = ip.split('.')
for i in ip_list:
new_i = bin(int(i))
if len(new_i) >= 10:
s += new_i[2:]
else:
new_i2 = new_i[2:].rjust(8, '0')
s += new_i2
print(int(s, base=2))
'''
# 方法二
'''
s = ''
ip_list = ip.split('.')
for i in ip_list:
new_i = bin(int(i))
new_i2 = new_i[2:].rjust(8, '0')
s += new_i2
print(int(s, base=2))
'''
# 方法三
'''
ip_list = ip.split('.')
sum = 0
n = 0
for i in ip_list:
sum += i * 256 ** (len(ip_list) - 1 - n)
n += 1
print(sum)
'''