Created
January 9, 2018 10:53
-
-
Save TannerRayMartin/c11abda9595400db4ef36839c8a2fe2e to your computer and use it in GitHub Desktop.
After programming for a year I re-wrote IP to Binary. making the same output with 1/3 of the lines.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class converter: | |
def __init__(self): | |
self.ip = input('Enter an IP Address: ') | |
self.binary = [128,64,32,16,8,4,2,1] | |
self.empty_list = [] | |
def convert(self, number): | |
empty_string = '' | |
number = int(number) | |
for num in self.binary: | |
if number >= num: | |
empty_string += '1' | |
number -= num | |
else: | |
empty_string += '0' | |
return empty_string | |
def seperate(self, ip): | |
ip = ip.split('.') | |
return ip | |
def main(self): | |
for num in C.seperate(self.ip): | |
new = C.convert(num) | |
self.empty_list.append(new) | |
print('Your IP: ' + '.'.join(self.empty_list)) | |
C = converter() | |
C.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment