You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
3 years ago
|
from converter import decToBin, binToDec
|
||
|
|
||
|
# True: convert from decimal to binary
|
||
|
# False: convert from binary to decimal
|
||
|
convertToBinary = True
|
||
|
|
||
|
print(''' ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ _________ ____ ____ ____ ____ ____ ____ ____ ____ ____
|
||
|
||B |||i |||n |||a |||r |||y |||/ |||D |||e |||c |||i |||m |||a |||l ||| |||C |||o |||n |||v |||e |||r |||t |||e |||r ||
|
||
|
||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||__|||_______|||__|||__|||__|||__|||__|||__|||__|||__|||__||
|
||
|
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/_______\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
|
||
|
''')
|
||
|
|
||
|
print("""Would you like to convert from
|
||
|
1. Decimal to binary
|
||
|
2. Binary to decimal
|
||
|
""")
|
||
|
|
||
|
# Get choice
|
||
|
choiceIn = int(input())
|
||
|
|
||
|
# Get 1 or 2, if neither then keep looping
|
||
|
while True:
|
||
|
match choiceIn:
|
||
|
case 1:
|
||
|
convertToBinary = True
|
||
|
break
|
||
|
case 2:
|
||
|
convertToBinary = False
|
||
|
break
|
||
|
case _:
|
||
|
print("Not a valid choice.")
|
||
|
continue
|
||
|
|
||
|
if (convertToBinary):
|
||
|
print('''
|
||
|
======================================================================
|
||
|
CONVERTING DECIMAL TO BINARY (please separate your inputs with spaces)
|
||
|
======================================================================
|
||
|
''')
|
||
|
decListIn = map(int, input().split(" "))
|
||
|
print ("\n\nOutput:")
|
||
|
for i in decListIn:
|
||
|
print(decToBin(i))
|
||
|
else:
|
||
|
print('''
|
||
|
======================================================================
|
||
|
CONVERTING BINARY TO DECIMAL (please separate your inputs with spaces)
|
||
|
======================================================================
|
||
|
''')
|
||
|
print ("\nOutput:\n")
|
||
|
binListIn = map(str, input().split(" "))
|
||
|
for i in binListIn:
|
||
|
print(binToDec(i))
|
||
|
|
||
|
print("\n\n")
|