-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIP Converter.py
More file actions
37 lines (29 loc) · 875 Bytes
/
Copy pathIP Converter.py
File metadata and controls
37 lines (29 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
usrInput = ""
numList = []
binIntermediary = ""
binOutput = ""
def stringReverse(x):
return x[::-1]
usrInput = str(input("\nPlease enter the IP address you would like to convert: "))
numList = usrInput.split(".")
leng = len(numList)
while leng > 0:
numList[leng - 1] = int(numList[leng - 1])
leng = leng -1
leng = len(numList)
while leng > 0:
count = 8
while count > 0:
if numList[leng - 1] % 2 > 0:
numList[leng - 1] = (numList[leng - 1] -1) / 2
binIntermediary = binIntermediary + "1"
count = count -1
else:
numList[leng - 1] = numList[leng - 1] / 2
binIntermediary = binIntermediary + "0"
count = count -1
binOutput = binOutput + binIntermediary
binIntermediary = " "
leng = leng -1
binOutput = stringReverse(binOutput)
print(f"\n{binOutput}\n")