NumeralSystemConverter.py released
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
print("©KOTIKOT, script by BarsTiger")
|
print("©KOTIKOT, script by BarsTiger")
|
||||||
print()
|
print()
|
||||||
print("Please, type only int numbers, str is allowed only in hex")
|
print("Please, type only int numbers, str is allowed only in hex")
|
||||||
|
print("To change system, press Ctrl+C or close window and rerun program with new settings")
|
||||||
|
|
||||||
hextonum = {
|
hextonum = {
|
||||||
"0": 0,
|
"0": 0,
|
||||||
@@ -21,6 +22,13 @@ hextonum = {
|
|||||||
"F": 15
|
"F": 15
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getkeybyval(val, dictionary):
|
||||||
|
keys = []
|
||||||
|
for key in list(dictionary):
|
||||||
|
if dictionary[key] == val:
|
||||||
|
keys.append(key)
|
||||||
|
return keys
|
||||||
|
|
||||||
systypefrom = int(input("Type base number of system convert FROM: "))
|
systypefrom = int(input("Type base number of system convert FROM: "))
|
||||||
systypeto = int(input("Type base number of system convert TO: "))
|
systypeto = int(input("Type base number of system convert TO: "))
|
||||||
if systypefrom > 16 or systypeto > 16:
|
if systypefrom > 16 or systypeto > 16:
|
||||||
@@ -38,7 +46,23 @@ def todecimal(number, base):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def fromdecimal(number, base):
|
||||||
|
remainders = []
|
||||||
|
result = str()
|
||||||
|
|
||||||
|
while number != 0:
|
||||||
|
remainders.insert(0, number % base)
|
||||||
|
number = number // base
|
||||||
|
|
||||||
|
for symbol in remainders:
|
||||||
|
result += getkeybyval(int(symbol), hextonum)[0]
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
inputnumber = input("Type number, that you want to convert: ")
|
inputnumber = input("Type number, that you want to convert: ")
|
||||||
inputnumber = inputnumber.upper()
|
inputnumber = inputnumber.upper()
|
||||||
print(todecimal(inputnumber, systypefrom))
|
|
||||||
|
numtoprint = fromdecimal(todecimal(inputnumber, systypefrom), systypeto)
|
||||||
|
|
||||||
|
print(numtoprint)
|
||||||
|
|||||||
Reference in New Issue
Block a user