def dec_to_bin(ip):
ip_array = ip.split(".")
ip_array = filter(None, ip_array)
if len(ip_array) != 4:
return "Invalid IP Address format"
else:
ip_bin = []
for x in range(len(ip_array)):
# Formatting example referenced from:
# http://stackoverflow.com/a/10411108/1170681
ip_bin.append('{0:08b}'.format(int(ip_array[x])))
ip_bin.append(".")
ip_bin.pop()
return ''.join(ip_bin)
This is a simple parser that will take a IP Address in decimal form and convert it into the binary representation.
I'm looking for any tips on coding styles and improving the efficiency of the code.